B
B
batalek2021-01-26 13:55:12
Python
batalek, 2021-01-26 13:55:12

How to make "help" command with multi-pages?

600ff3f3d58fe014487202.png
how to make just such a command with pages, navigation by reactions. 600ff43b43b70178936695.png
this is the second page and so on
. One feature is that everything is done beautifully in embed. Please do this please.

I use this one but the worst thing is that there is no embed and when you get to the last page it doesn't scroll anymore. Still a lot of buggy.

@bot.command()
async def pages(ctx):
    contents = ["This is page 1!", "This is page 2!", "This is page 3!", "This is page 4!"]
    pages = 4
    cur_page = 1
    message = await ctx.send(f"Page {cur_page}/{pages}:\n{contents[cur_page-1]}")
    # getting the message object for editing and reacting

    await message.add_reaction("◀️")
    await message.add_reaction("▶️")

    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 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(content=f"Page {cur_page}/{pages}:\n{contents[cur_page-1]}")
                await message.remove_reaction(reaction, user)

            elif str(reaction.emoji) == "◀️" and cur_page > 1:
                cur_page -= 1
                await message.edit(content=f"Page {cur_page}/{pages}:\n{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 asyncio.TimeoutError:
            await message.delete()
            break
            # ending the loop if user doesn't react after x seconds

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2021-01-26
@batalek

https://github.com/Rapptz/discord-ext-menus

B
beheh, 2022-03-06
@beheh

https://github.com/RuCybernetic/Cybernator/blob/ma...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question