#python-3.x #discord.py
Вопрос:
У меня на сервере есть процесс проверки, который принимает данные нового участника (имя, раздел и т. Д.), а затем отправляет их на канал на сервере, где администраторы нажимают на эмоцию, чтобы принять/отклонить человека. Проблема в том, что как только 2 человека открывают билеты, они в основном становятся непригодными для использования.
Чтобы я был в здравом уме во время написания, я составлю сценарий.
x
,y
присоединяйтесь к серверу.- Оба отправляют запросы на проверку.
- Администратор принимает запрос на
x
. - Вместо
x
того, чтобы быть одобренным,x
иy
получает одобрение.
Это действительно беспокоит меня, так как я мог бы с таким же успехом сделать это без wait_for()
проверок.
Код:
@commands.Cog.listener()
async def on_member_join(self, member: discord.Member):
channel = member.guild.get_channel(734637251681583164)
verichannel = member.guild.get_channel(849593765097373696)
embed = discord.Embed(
title=f"Welcome {member.name}, keep in mind that this is NOT an [woah privacy] server!",
description=f"This is not a family-friendly server, so please leave if you're not comfortable with it. n Make sure to read <#734639183737389060> amp; <#750190162000216215> before proceeding! n To get access to our server, please verify at <#848430448223977512>.",
color=0x2ecc71
)
embed.set_thumbnail(url=member.avatar_url)
await channel.send(member.mention, embed=embed)
# DM verification
def check(m):
return m.guild == None and m.author == member
awaitingverification = discord.Embed(title="Verification Request", description=f"User: {member.mention}", color = 0x01c618)
embed= discord.Embed(title="What is this?",
description="This is a verification program for the unofficial [woah privacy] server. We do this to ensure the safety and privacy of our members. We are going to ask information that will be sent to our admins for further processing.",
color=0x00d118)
embed.set_author(name="[woah privacy] Verification program")
embed.add_field(name="1st Question: What is your first name?", value="Example: Jordan",
inline=False)
await member.send(embed=embed)
try:
first_name = await self.bot.wait_for('message',timeout=30, check=check)
except asyncio.TimeoutError:
await member.send("Timed out. Re-Join.")
return
awaitingverification.add_field(name="First Name", value=first_name.content, inline=True)
embed = discord.Embed(title="Verification: 2nd step",
description="This is the second step of the verification process.", color=0x00d118)
embed.set_author(name="[woah privacy] Verification program")
embed.add_field(name="2nd Question: What is your section? If you are not enrolled, reply 'Visitor'.", value="Example: LS208", inline=False)
await member.send(embed=embed)
try:
section = await self.bot.wait_for('message',timeout=30, check=check)
except asyncio.TimeoutError:
await member.send("Timed out. Re-Join.")
return
awaitingverification.add_field(name="Section", value=section.content, inline=True)
embed = discord.Embed(title="Verification: 3rd step",
description="This is the third step of the verification process.", color=0x00d118)
embed.set_author(name="[woah privacy] Verification program")
embed.add_field(name="3rd Question: Do you agree with all our rules? Reply with 'Yes' if you do.",
value="Below is a skimmed version of our full rules, so be sure to read them after.",
inline=False)
embed.add_field(name="This is not an official [woah privacy] server.", value="If there is one, then... we dont care.",
inline=False)
embed.add_field(name="Names in the server are your real first names.", value="If not: kicked out the door.",
inline=False)
embed.add_field(name="This is not a family friendly server.",
value="It's a mess here sometimes but thats what's good about it.", inline=False)
embed.add_field(name="Don't be an asshole.", value="We wont hesitate to swing that ban hammer.", inline=False)
embed.add_field(name="No loopholes.", value="Because.. Well... It's bad.", inline=False)
embed.add_field(name="Read the Discord ToS (Terms of Service)", value="TL:DR: Must be 13 to use discord.",
inline=False)
await member.send(embed=embed)
try:
rulestatus = await self.bot.wait_for('message',timeout=30, check=check)
except asyncio.TimeoutError:
await member.send("Timed out. Re-Join.")
return
awaitingverification.add_field(name="Rules", value=rulestatus.content, inline=True)
awaitingverification.set_footer(text="🟩: Student, 🟨: Visitor, 🟥: Deny and Kick")
await member.send("Thank you. Your application will be processed in due time.")
verification = await verichannel.send(embed=awaitingverification)
await verification.add_reaction("🟩")
await verification.add_reaction("🟨")
await verification.add_reaction("🟥")
def check(reaction, user):
return str(reaction.emoji) in ["🟩", "🟨", "🟥"] and user != self.bot.user
reaction, user = await self.bot.wait_for("reaction_add", check=check)
if str(reaction.emoji) == "🟩":
embed = discord.Embed(title="Verification Request", description=f"User: {member.mention}")
embed.add_field(name="Status:", value=f"Approved by {user}: Student", inline=False)
await verification.edit(embed=embed)
await verification.clear_reactions()
role1 = discord.utils.get(member.guild.roles, name="Students")
await member.add_roles(role1)
if discord.utils.get(member.guild.roles, name=f"Section: {section.content}"):
sectionrole = discord.utils.get(member.guild.roles, name=f"Section: {section.content}")
await member.add_roles(sectionrole)
else:
await member.guild.create_role(name=f"Section: {section.content}")
sectionrole = discord.utils.get(member.guild.roles, name=f"Section: {section.content}")
await member.add_roles(sectionrole)
await member.send("Your Verification Request has been granted as Student. Have a good time and check the rules!")
return
elif str(reaction.emoji) == "🟨":
embed = discord.Embed(title="Verification Request", description=f"User: {member.mention}")
embed.add_field(name="Status:", value=f"Approved by {user}: Visitor", inline=False)
await verification.edit(embed=embed)
await verification.clear_reactions()
role2 = discord.utils.get(member.guild.roles, name="Visitors")
await member.add_roles(role2)
await member.send("Your Verification Request has been granted as Visitor. Have a good time and check the rules!")
return
elif str(reaction.emoji) == "🟥":
embed = discord.Embed(title="Verification Request", description=f"User: {member.mention}")
embed.add_field(name="Status:", value=f"Denied by {user}", inline=False)
await verification.edit(embed=embed)
await verification.clear_reactions()
await member.send("Your Verification Request has been denied.")
await member.kick()
return
p.s извините, я не просматривал код, я хотел поделиться им как есть, потому что, возможно, это вина моих спагетти.
Ответ №1:
Чтобы решить эту проблему, проверьте, совпадает ли это сообщение в check
:
verification = await verichannel.send(embed=awaitingverification)
await verification.add_reaction("🟩")
await verification.add_reaction("🟨")
await verification.add_reaction("🟥")
def check(reaction, user):
return str(reaction.emoji) in ["🟩", "🟨", "🟥"] and user != self.bot.user and reaction.message == verification
reaction, user = await self.bot.wait_for("reaction_add", check=check)
Рекомендации: