Shippai
Shippai

Reputation: 41

discord.py wait_for('reaction_add') functioning differently with direct messages

My goal is to have the bot react to it's own message and then send a reply in that channel if the user who sent the original command reacts as well. Right now the function works if the command is sent in a server channel, but if sent as a direct message to the bot, it doesn't wait for your reaction. By printing the values of user.id and ctx.author.id during the check, I noticed that the bot checks it's own reaction sometimes (user.id returns the bot's id). I'm not sure if this is related because it waits for a reaction from the correct user in server channels regardless.

API Documentation for wait_for() and on_reaction_add

I'd like this function to work in servers and direct messages to the bot, am I missing something? Thanks!

@bot.command()
async def hello(ctx):
    msg = await ctx.send(f'Hi {ctx.author.mention}')
    await msg.add_reaction('✅')

    def check(reaction, user):
        print(user.id, ctx.author.id)
        return reaction.message.id == msg.id and user.id == ctx.author.id and str(reaction.emoji) == '✅'

    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
    except asyncio.TimeoutError:
        pass
    else:
        await ctx.send('success')

Upvotes: 2

Views: 777

Answers (2)

you can check the reactionary id

    def check(reaction, user):
        # let the user id str 
        print(str(reaction.author.id), str(ctx.author.id))
        return reaction.message.id == msg.id and reaction.author.id == ctx.author.id and str(reaction.emoji) == '✅'

    try:
        # wait for the reactions
        reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
    except asyncio.TimeoutError as error:
        pass
    else:
        # except an error
        await ctx.send('success')

Upvotes: 0

Shippai
Shippai

Reputation: 41

It was an intents issue after all, same permission issue as this post. After intents = discord.Intents.default() you also need to enable server members privileged intent for your application here and set intents.members = True in your code to give a bot the required permissions for this to work in DMs

Upvotes: 2

Related Questions