Discord.py detecting reactions

Viewed 3824

I am making a Discord.py bot that uses DMs. I have a command where the bot will DM you asking for you to react to the action you are trying to do the issue is when the user adds the reaction it doesn't work.

Here's what I have so far

@client.command()
async def suggest(ctx):
        embed = discord.Embed(
            title = 'What kind of suggestion are you making?',
            description = '<:Yes:755187983585509517> Car Suggestion\n<:Maybe:755187983623258123> Job Suggestion\n<:No:755187984067854367> Other Suggestion Type',
            colour = discord.Colour.green()
        )

        await ctx.message.delete()
        await ctx.send(f'{ctx.message.author.mention} Please check your DMs to continue!')

        embed.set_footer(text='Pembroke Pines Bot - Made By: parker02311')

        msg = await ctx.author.send(embed=embed)
        await msg.add_reaction('<:Yes:755187983585509517>')
        await msg.add_reaction('<:Maybe:755187983623258123>')
        await msg.add_reaction('<:No:755187984067854367>')

        def check(reaction, user):
            return user == msg.author and str(reaction.emoji) == '<:Yes:755187983585509517>'

        try:
            reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
        except asyncio.TimeoutError:
            await ctx.author.send("Timed out")
        else:
            embed = discord.Embed(
                title = 'Car Suggestion',
                description = 'What is your username?',
                colour = discord.Colour.green()
            )

            embed.set_footer(text='Pembroke Pines Bot - Made By: parker02311')
            await ctx.author.send(embed=embed)
            
            def check(m):
                return m.content
            msg = await client.wait_for('message', check=check)
            await ctx.author.send(f'Okay, your username is: **{msg}**')

            embed = discord.Embed(
                title = 'Car Suggestion',
                description = 'What is the car model?',
                colour = discord.Colour.green()
            )

            embed.set_footer(text='Pembroke Pines Bot - Made By: parker02311')
            await ctx.author.send(embed=embed)
            msg = await client.wait_for('message', check=check)
            await ctx.author.send(f'Okay, the model is: **{msg}**')

        #channel = client.get_channel(734882692537253900)
        embed = discord.Embed(
            description = f'{ctx.message.author.mention} **made a suggestion\nChannel:** {ctx.message.channel}\n**Message Content:** {ctx.message.content}',
            colour = discord.Colour.red()
        )
        embed.set_footer(text='Pembroke Pines Bot - Made By: parker02311')
        embed.set_author(name=ctx.message.author)
        await logschannel.send(embed=embed)

That's taken pretty much straight out of the discord.py docs. https://discordpy.readthedocs.io/en/latest/api.html#discord.Client.wait_for

3 Answers

So it turns out

return user == msg.author and str(reaction.emoji) == '<:Yes:755187983585509517>'

I was checking the BOT adding a reaction not the user, hopefully this saves someone else time.

Here is a suggestion command I came up with:

@client.command()
async def suggest(ctx, *, suggestion):
    author = ctx.message.author
    file = open("suggestions.txt", "a+")
    file.write(str(author) + " : " + suggestion + "\n")
    embed = discord.Embed(title='Suggestion',
                          description="This Was Suggested By",
                          color=0xE0B802)

    embed.set_footer(text=f"Made By {ctx.author.mention}")
    embed.set_author(name=f"{author}")
    embed.add_field(name=author, value=suggestion)
    await ctx.send("Suggestion Submitted")
    msg = await channel.send(embed=embed)
    await msg.add_reaction('')
    await msg.add_reaction('')
    await ctx.send(f"{ctx.author.mention} suggested {suggestion}!")

It will send an embed with the suggestion and add the reactions along with having the author that created the suggestion in its footer.

you could try a wait_for. Examples are here

@client.event
async def on_message(message):
    if message.content.startswith('$thumb'):
        channel = message.channel
        await channel.send('Send me that  reaction, mate')

        def check(reaction, user):
            return user == message.author and str(reaction.emoji) == ''

        try:
            reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
        except asyncio.TimeoutError:
            await channel.send('')
        else:
            await channel.send('')

(taken from the discord.py API reference https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.wait_for

Related