discord.py "wait_for" a reaction in a command

Question:

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')
Asked By: puncher

||

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:

Answered By: Diggy.
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.