在等待调用多个"wait_fo(reaction_add)"时,如何修复我的discord bot中



我的服务器上有一个验证过程,它接受新成员的输入(名字和章节等(,然后将其发送到服务器中的一个通道,管理员在那里点击表情接受/拒绝该人。问题是,一旦超过2个人打开门票,它基本上就无法使用了。

为了让我在写的时候保持理智,我会做一个场景。

  1. xy加入服务器
  2. 两者都发送验证请求
  3. 管理员接受x的请求
  4. xy将获得批准,而不是批准x

这真的很困扰我,因为我还不如不进行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> & <#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

抱歉,我没有浏览任何代码,我想按原样分享,因为这可能是我意大利面条的错。

要解决此问题,请检查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)

参考文献:

  • 反应消息

最新更新