Discord.py“wait_for”命令中的反应

pun*_*her 5 python discord.py

我有一个将嵌入发送到特定频道的命令。然后机器人会添加对此消息的反应。到目前为止,这有效。

现在,当有人点击此反应时,我希望机器人回复一条消息。但这是行不通的。没有错误,这意味着它以某种方式工作,但不是我想要的。

@bot.command()
async def buy(ctx, choice):
    # some code ...

    mess1 = await channel.send(embed=embed)
    await mess1.add_reaction('<a:check:674039577882918931>')

    def check(reaction, user):
        return reaction.message == mess1 and str(reaction.emoji) == '<a:check:674039577882918931>'

    await bot.wait_for('reaction_add', check=check)
    channeldone = bot.get_channel(705836078082424914)
    await channeldone.send('test')
Run Code Online (Sandbox Code Playgroud)

Dig*_*gy. 2

看来你的reaction.message == mess1情况正在恢复False,我无法缩小范围来解释为什么会发生这种情况,但如果我这样做的话,我会编辑它。

解决这个问题的一种方法是评估消息的 ID:

return reaction.message.id == mess1.id and str(reaction.emoji) == '<a:check:674039577882918931>'
Run Code Online (Sandbox Code Playgroud)

这将评估True机器人何时做出反应,因此我建议添加另一个条件来检查用户是否做出反应(如果您希望用户这样做):

return .... and user == ctx.author
Run Code Online (Sandbox Code Playgroud)

参考: