Using Reaction Menus#

Pagination#

The meat of the library is the Menu class but a MenuPages class is provided for the common use case of actually making a pagination session.

The MenuPages works similar to Menu except things are separated into a PageSource. The actual MenuPages rarely needs to be modified, instead we pass in a PageSource that deals with the data representation and formatting of the data we want to paginate.

The library comes with a few built-in page sources:

None of these page sources deal with formatting of data, leaving that up to you.

For the sake of example, here’s a basic list source that is paginated:

from nextcord.ext import menus

class MySource(menus.ListPageSource):
    def __init__(self, data):
        super().__init__(data, per_page=4)

    async def format_page(self, menu, entries):
        offset = menu.current_page * self.per_page
        return '\n'.join(f'{i}. {v}' for i, v in enumerate(entries, start=offset))

@bot.command()
async def pages_example(ctx):
    data = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
    pages = menus.MenuPages(source=MySource(data), clear_reactions_after=True)
    await pages.start(ctx)

The PageSource.format_page() can return either a str for content, nextcord.Embed for an embed, List[nextcord.Embed] for sending multiple embeds, or a dict to pass into the kwargs of nextcord.Message.edit().