Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

discord.py "wait_for" a reaction in a command

I have a command which sends an embed to a specific channel. The bot then adds a reaction to this message. That works so far.

Now, when someone clicks on this reaction, I want the bot to respond with a message. But that doesn't work. There is no error, which means that it works in some way, but not like I want.

@bot.command()
async def buy(ctx, choice):
    # some code ...

    mess1 = await channel.send(embed=embed)
    await mess1.add_reaction('<a:check:674039577882918931>')

    def check(reaction, user):
        return reaction.message == mess1 and str(reaction.emoji) == '<a:check:674039577882918931>'

    await bot.wait_for('reaction_add', check=check)
    channeldone = bot.get_channel(705836078082424914)
    await channeldone.send('test')
like image 453
puncher Avatar asked Nov 07 '22 07:11

puncher


1 Answers

It looks as though your reaction.message == mess1 condition is returning False, and I can't narrow it down as to why that's happening, but I'll edit this if I do.

A way to overcome this would be to evaluate the IDs of the messages:

return reaction.message.id == mess1.id and str(reaction.emoji) == '<a:check:674039577882918931>'

And this will evaluate to True when the bot reacts, so I'd recommend adding another condition to check that the user reacted, if that is what you want the user to do:

return .... and user == ctx.author

References:

  • Message.id
  • discord.Member
like image 151
Diggy. Avatar answered Nov 14 '22 23:11

Diggy.