0
votes

How would I be able to wait for a reaction and then use that reaction as a response

What I want the code to do:

User -> .buy

Bot -> "How would you like to purchase"

User -> Reacts with 1️⃣

Bot -> Says response for reaction 1️⃣

Here is my code so far:

message = await ctx.send("How would you like to purchase") 
for emoji in ('0️⃣', '1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣'): 
    await message.add_reaction(emoji)

I want the bot to be able to respond to each of these reactions with different responses

1

1 Answers

1
votes

If you're trying to wait for a response from a reaction you can try using the on_reaction_add event. Something like this may work:

@client.event
async def on_reaction_add(reaction, user):
    if reaction.message.author.bot:     #checks if message is from bot
        if reaction.emoji == '0️⃣':
            #process for this reaction
        elif reaction.emoji == '1️⃣':
            #process for this reaction
        #this goes on for as many reactions you have

Alternatively you can use a switch instead of a block of if elif statements. You can use a switch statement like this: switch = {'0️⃣':#process,'1️⃣':#process, #and so on}

With this you can do:

switch.get(reaction.emoji)

This will get the process from the specific reaction in the switch statement. I hope this may be of help.