Midoss
Midoss

Reputation: 35

Reaction Check with discord.py

I was working on a command which will send a nuke gif if you react bot with an agree reaction. This works fine however I cant make bot answer diffrently if you choose other option or timeout. My current code is bellow. Thanks for your help

async def nuke(ctx):
    
    yas = '✔️'
    nay = '❌'
    
    message = await ctx.send("Are you sure that you want to use your nukes?")
    
    await message.add_reaction(yas)
    await message.add_reaction(nay)
    
    
    def check(reaction, user):
        return user == ctx.author and str(reaction.emoji) == '✔️'
    await bot.wait_for('reaction_add', timeout=60.0, check=check)
        
    embed = discord.Embed(title="Code: 759245 Activated. Destruction of Channel started")
    embed.set_image(url="https://i.gifer.com/3Tt5.gif")
    await ctx.send(embed=embed)
    
    def check(reaction, user):
        return user == ctx.author and str(reaction.emoji) == '❌'
    await bot.wait_for('reaction_add', timeout=60.0, check=check)

    await ctx.send("Cancelled")```

Upvotes: 1

Views: 4696

Answers (1)

stijndcl
stijndcl

Reputation: 5650

Code goes top to bottom, meaning that what your code will do now is the following:

  • Wait for the user to react '✔️'
  • Send gif 3Tt5
  • Wait for the user to react '❌'
  • Send "Cancelled"

You're gonna want to write one check that checks if any of the possible reactions was used, and then handle all of them differently.

yas = '✔️'
nay = '❌'

valid_reactions = ['✔️', '❌']

def check(reaction, user):
    return user == ctx.author and str(reaction.emoji) in valid_reactions
reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)

if str(reaction.emoji) == yas:
    embed = # code to create the embed
    return await ctx.send(embed=embed)

# there's only two reactions, so if the above function didn't return, it means the second reaction (nay) was used instead
await ctx.send("Cancelled")

Upvotes: 2

Related Questions