如何让机器人等待2个反应



我想让我的Discord.py机器人等待2个反应。。。

代码:

def check(reaction, user):
return user == message.author and str(reaction.emoji) == '1️⃣'
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '2️⃣'
mm = await message.send(embed=embed1)
await mm.add_reaction("1️⃣")
await mm.add_reaction("2️⃣")
reaction, user = await bot.wait_for("reaction_add",check=check,timeout=180)
reaction, user = await bot.wait_for("reaction_add",check=check,timeout=180)
if reaction:
await mm.edit(embed=embed1)
elif reaction:
await mm.edit(embed=embed3)

check函数中,您可以检查用户的反应是否在给定列表中,也可以使用or statement。在这个例子中,我将使用前者。然后,你可以检查它是哪种反应,然后从那里继续。请查看下面的修订代码。

def check(reaction, user):
# Check if user is the author of the message
# AND if the reaction emoji is in a list of set reactions, 1️⃣ and 2️⃣
return user == ctx.author and str(reaction.emoji) in ["1️⃣","2️⃣"]
await mm.add_reaction("1️⃣")
await mm.add_reaction("2️⃣")
reaction, user = await bot.wait_for("reaction_add",check=check,timeout=180)
if str(reaction.emoji) == "1️⃣":
# do something
elif str(reaction.emoji) == "2️⃣":
# do something else

最新更新