1
votes

So the following code has an issue that I haven't been able to solve.

The bot sends a second "testMessasge" and puts the reaction on that message as well as the main message. The issue here is I can react to either message to trigger the code when I ONLY want a reaction to the first message to be considered.

Would appreciate any help.

async def foo(ctx, booleanValue, randomClass, stringValue='', otherData=None):
    files, embed = createEmbed(ctx, randomClass)
    message = await ctx.send(files=files, embed=embed)
    await message.add_reaction(data.getEmoji('1'))

    testMessage = await ctx.send('TEST')
    await testMessage.add_reaction(data.getEmoji('1'))

    def check(reaction, user):
        return (user == ctx.message.author and str(reaction.emoji) == data.getEmoji('1'))
    
    async def waitForEmoji(ctx, isBattle):
        print(ctx.message.author)
        try:
            reaction, user = await bot.wait_for('reaction_add', timeout=300.0, check=check)
        except asyncio.TimeoutError:
            await ctx.send(ctx.message.author.display_name + 's connection closed.')
        else:
            print(user)
            print(ctx.message.author)
1

1 Answers

0
votes

In the note written in the doc for on_reaction_add they mention that you can use reaction.message to get the message being reacted to.

If we implement this in our check, we get:

    def check(reaction, user):
        return (
            user == ctx.message.author
            and str(reaction.emoji) == data.getEmoji('1')
            and reaction.message == message # What you called your first message
            )

This makes the bot only trigger if the reaction is added to the first message