如何让机器人响应特定反应? Discord.py

How do I make a bot respond to a specific reaction? Discord.py

我正在尝试向我的 discord 机器人添加赠品功能,但我尝试制作的重新滚动功能不起作用。当赠品结束时,它会发送一条消息,说明谁赢得了赠品。这就是我定义的重投。然后我让机器人等待,看看是否有人对此消息添加了 'x' 反应。我正在努力做到这一点,如果有人添加了 'x' 反应,那么它将在赠品中重新选择获胜者。如果多个获胜者无效,我希望也能重复此功能。但我不确定如何让机器人专门响应消息的特定反应。

reroll = await channel.send(f'Congratulations! {winner.mention} won {prize}!')

if reroll.reactions == '❌':

    winner2 = random.choice(users)

    await channel.send(f'Congratulations! {winner2.mention} won {prize}!')

根据discord documentation,我们可以查on_reaction_add(reaction, user)

Called when a message has a reaction added to it. Similar to on_message_edit(), if the message is not found in the internal message cache, then this event will not be called. Consider using on_raw_reaction_add() instead.

有了它你基本上可以检查消息

async def on_reaction_add(reaction, user):
  if 'Congratulations!' in reaction.message.content and reaction.emoji == '❌':
    # do stuff

您可以通过Reaction.message

访问正在回复的消息