Discord.py 如何根据用户反应执行操作

Discord.py How to do an action depending on the user reaction

如何检查用户反应?我正在使用该代码:

@client.command()
async def react(ctx):
    message = await ctx.send("Test")
    await question.add_reaction("<>")
    await question.add_reaction("<>")

如果用户对消息作出反应,我该如何执行操作?如果用户对消息作出反应,我该如何执行另一个操作?提前谢谢你

documentation 中你可以找到 client.wait_for() 等待事件发生。文档中的示例应该可以帮助您:

@client.event
async def on_message(message):
    if message.content.startswith('$thumb'):
        channel = message.channel
        await channel.send('Send me that  reaction, mate')

        def check(reaction, user):
            return user == message.author and str(reaction.emoji) == ''

        try:
            reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
        except asyncio.TimeoutError:
            await channel.send('')
        else:
            await channel.send('')