【问题标题】:How To Make Bot Wait For 2 Reactions如何让机器人等待 2 次反应
【发布时间】:2022-01-23 09:13:36
【问题描述】:

我希望我的 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 函数?
  • ok 生病添加检查功能

标签: python discord discord.py message


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-09-26
    • 2023-03-14
    • 2020-02-23
    • 1970-01-01
    • 2020-11-07
    • 2021-03-22
    • 2020-05-24
    • 2021-08-18
    • 1970-01-01
    相关资源
    最近更新 更多