Discord.py reaction menus responding to reactions on all active menus

I am trying to create a help menu for my discord.py (I am using discord.py V2.0 however there is not many major differences regarding this) bot however I am having a very big bug with part of the code. It all runs as normal and outputs/responds to the correct things, however, it will respond to any active help message (any message that has not timed out)

The photo I have attached shows the two help messages (created using separate commands), the issue is that it will respond to reactions on both of those (and any others that exist) even though they were created separately.

Photo of the help messages

Here is my code:

@commands.command()
    async def help(self, ctx, command=None):
        p = cluster["Atomic_Developer_Bot"]["prefix"].find_one({"guild_id": ctx.guild.id})["prefix"]
        messageid = ctx.message.id
        # ------------------ IF COMMAND == NONE --------------------------- #
        page_one = discord.Embed(title="\u200b", color=0x008000)
        page_one: Embed = discord.Embed(
            colour=discord.Color.teal()
        )
        page_one.add_field(name="**Atomic Help**", value=f"Welcome to Atomic!\nFor help with individual commands please do **{p}help <command>**\n      \nFor more support with the bot do **+support**\n     \nUse the reactions below to navigate the help message!")
        page_one.timestamp = datetime.datetime.utcnow()
        page_one.set_footer(text='Page 1/5 \u200b')

        page_two = discord.Embed(title="\u200b", color=0x008000)
        page_two: Embed = discord.Embed(
            description=("**Setup Commands**"),
            colour=discord.Color.teal()
        )
        page_two.add_field(name=f'**{p}setup** - Detailed description of the below commands', value=f"Enable logging commands:\n```{p}enablemod,{p}enablemessage,{p}enablemember,{p}enablevoice,{p}enablechannel,{p}enablejoin,{p}enableleave,{p}enablewelcome,{p}enablegoodbye,{p}enableall```\n        \nDisable logs commands:\n```{p}disablemod,{p}disablemessage,{p}disablemember,{p}disablevoice,{p}disablechannel,{p}disablejoin,{p}disableleave,{p}disablewelcome,{p}disablegoodbye,{p}disableall```")
        page_two.timestamp = datetime.datetime.utcnow()
        page_two.set_footer(text='Page 2/5 \u200b')

        page_three = discord.Embed(title="\u200b", color=0x008000)
        page_three: Embed = discord.Embed(
            description=('**Fun Commands**'),
            colour=discord.Color.teal()
        )
        page_three.add_field(name=f'**{p}funhelp** - Detailed description of the below commands', value=f"Fun commands:\n ```{p}8ball,{p}topic,{p}coin,{p}insta,{p}tiktok,{p}avatar,{p}meme,{p}claptext```\n         \nAnimal Commands:\n```{p}cat,{p}fox,{p}panda,{p}redpanda,{p}koala,{p}dog,{p}bird```")
        page_three.timestamp = datetime.datetime.utcnow()
        page_three.set_footer(text='Page 3/5 \u200b')

        page_four = discord.Embed(title="\u200b", color=0x008000)
        page_four: Embed = discord.Embed(
            description=('**Utility Commands**'),
            colour=discord.Color.teal()
        )
        page_four.add_field(name=f'**{p}utilityhelp** - Detailed description of the below commands', value=f'Utility commands:\n```{p}serverinfo,{p}userinfo,{p}support,{p}invite,{p}suggest,{p}error,{p}changeprefix,{p}partner,{p}credits,{p}status```')
        page_four.timestamp = datetime.datetime.utcnow()
        page_four.set_footer(text='Page 4/5 \u200b')

        page_five = discord.Embed(title="\u200b", color=0x008000)
        page_five: Embed = discord.Embed(
            description=('**Moderation Commands**'),
            colour=discord.Color.teal()
        )
        page_five.add_field(name=f'**{p}modhelp** - Detailed description of the below commands', value=f'Moderation commands:\n```{p}warn,{p}ban,{p}kick,{p}removewarn,{p}clearwarns,{p}unban,{p}mute,{p}unmute,{p}tempmute,{p}note,{p}removenote,{p}purge```')
        page_five.timestamp = datetime.datetime.utcnow()
        page_five.set_footer(text='Page 5/5 \u200b')

        if command == None:
            contents = [page_one, page_two, page_three, page_four, page_five]
            pages = 5
            cur_page = 1
            message = await ctx.send(embed = contents[cur_page-1])
            # getting the message object for editing and reacting
            await message.add_reaction("◀️")
            await message.add_reaction("▶️")
            
            if messageid == ctx.message.id:
                def check(reaction, user):
                    return user == ctx.author and str(reaction.emoji) in ["◀️", "▶️"]
                    # This makes sure nobody except the command sender can interact with the "menu"

                while True:
                    try:
                        reaction, user = await self.bot.wait_for("reaction_add", timeout=60, check=check)
                        # waiting for a reaction to be added - times out after x seconds, 60 in this
                        # example
                        if str(reaction.emoji) == "▶️" and cur_page != pages:
                            cur_page += 1
                            await message.edit(embed = contents[cur_page-1])
                            await message.remove_reaction(reaction, user)

                        elif str(reaction.emoji) == "◀️" and cur_page > 1:
                            cur_page -= 1
                            await message.edit(embed = contents[cur_page-1])
                            await message.remove_reaction(reaction, user)

                        else:
                            await message.remove_reaction(reaction, user)
                            # removes reactions if the user tries to go forward on the last page or
                            # backwards on the first page
                    except:
                        pass
                        # ending the loop if user doesn't react after x seconds

There is no errors when this occurs

Sorry if this is not worded well. Any help is appreciated

1 answer

  • answered 2021-10-20 16:33 moinierer3000

    In your check you can specify which message the reaction belongs to. You already defined your message as message before so you should only need to check if it is the correct one.

    def check(reaction, user):
        return user == ctx.author and str(reaction.emoji) in ["◀️", "▶️"] and reaction.message == message
    

    I cannot test this myself right now, very sorry for that but it should work. Hope this is somewhat useful.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum