Stiletto
Stiletto

Reputation: 65

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

How can I check for the user reaction? I'm using that code:

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

How can I do an action if the user react to the message with 💯 and another action if the user react to the message with 👍? Thank you in advance

Upvotes: 1

Views: 691

Answers (1)

chluebi
chluebi

Reputation: 1829

In the documentation you can find client.wait_for() which waits for an event to happen. The example from the documentation should help you out:

@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('👍')

Upvotes: 2

Related Questions