【问题标题】:how can i use the wait_for command to look out for two different reactions in discord.py?我如何使用 wait_for 命令在 discord.py 中寻找两种不同的反应?
【发布时间】:2020-08-10 09:23:02
【问题描述】:

我有一个机器人,它会询问用户是否确定他们输入了正确的信息,并向他们显示他们输入的内容。我希望他们对正确的竖起大拇指和不正确的大拇指做出反应,但我似乎无法让代码同时查看两者。这就是我所拥有的……有人知道该怎么做吗?

def isUser(reaction, user):
    return user == ctx.author and (str(reaction.emoji) == '????' or str(reaction.emoji) == '????')
    
try:
    reaction, user = await bot.wait_for('reaction_add', timeout=60, check=isUser)
except asyncio.TimeoutError:
    await msg.edit(embed=embedEnd)
else:
    for i in msg.reactions:
        if i.emoji == '????':
            if i.count > 1:
                await msg.edit(embed=embedFin)
        elif i.emoji == '????':
            if i.count > 1:
                await msg.edit(embed=embedEnd)

msg 是我的机器人的消息。

embedFin 是我想在他们对 ???? 做出反应时显示的嵌入。

embedEnd 是我想在他们与 ???? 反应时显示的嵌入。

bot 是 commands.Bot()。

如果您需要更多信息,请告诉我!谢谢 :D

【问题讨论】:

    标签: discord.py


    【解决方案1】:
    def isUser(reaction, user):
        return user == ctx.author and (str(reaction.emoji) == '?' or str(reaction.emoji) == '?')
        
    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=60, check=isUser)
    except asyncio.TimeoutError:
        await msg.edit(embed=embedEnd)
    else:
        if str(reaction.emoji) == '?':
            await msg.edit(embed=embedFin)
        else:
            await msg.edit(embed=embedEnd)
    

    【讨论】:

    • 哦,我很笨。谢谢你。大声笑。
    猜你喜欢
    • 2020-08-25
    • 1970-01-01
    • 2019-03-05
    • 2021-06-20
    • 2021-06-22
    • 2020-11-27
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    相关资源
    最近更新 更多