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

How To Make Bot Wait For 2 Reactions

我希望我的 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