How to handle user reactions in a Discord bot?

I’m working on a custom bot for my Discord server. I want it to ask users if they’re sure about doing a paid splash. The bot should post a message with two reaction options: :white_check_mark: and :x:.

Here’s what I’ve got so far:

@bot.command(name='splash')
async def paid_splash(ctx):
    query = await ctx.send('Ready for a paid splash?')
    await query.add_reaction('✅')
    await query.add_reaction('❌')
    await ctx.message.delete()
    
    # This part doesn't work
    bot.wait_for('reaction_add', timeout=10.0)
    await ctx.send('Confirmed')

The bot posts the message and adds reactions, but I can’t figure out how to check which reaction the user picked. If they choose :white_check_mark:, I want to add them to a queue (haven’t coded that part yet).

Any ideas on how to fix this? Code examples would be super helpful. Thanks!

I’ve dealt with reaction handling in Discord bots before, and here’s what worked for me:

You’re on the right track, but you need to modify your wait_for call. Try something like this:

def check(reaction, user):
    return user == ctx.author and str(reaction.emoji) in ['✅', '❌']

try:
    reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
    if str(reaction.emoji) == '✅':
        await ctx.send('Adding you to the queue...')
        # Add user to queue logic here
    else:
        await ctx.send('Splash cancelled.')
except asyncio.TimeoutError:
    await ctx.send('No response, cancelling splash.')

This waits for the specific user’s reaction and handles the result accordingly. Remember to import asyncio for the TimeoutError handling. Hope this helps!