Base class

This is the base paginator class. It is not meant to be used directly, but you can subclass it to create your own paginator.

class discord.ext.paginators.base_paginator.BaseClassPaginator(pages, *, per_page=1, author_id=None, check=None, always_allow_bot_owner=True, delete_after=False, disable_after=False, clear_buttons_after=False, message=None, add_page_string=True, timeout=180.0)[source]

Base class for all paginators.

Parameters:
  • pages (Sequence[Any]) –

    A sequence of pages to paginate. Supported types for pages:

    • str: Will be set as the content of the message.

    • discord.Embed: Will be appended to the embeds of the message.

    • discord.File: Will be appended to the files of the message.

    • discord.Attachment: Calls to_file() and appends it to the files of the message.

    • dict: Will be updated with the kwargs of the message.

    • Sequence[Any]: Will be flattened and each entry will be handled as above.

    Sequence = List, Tuple, etc.

    Any other types will probably be ignored. This attribute should be able to be set after the paginator is created. Aka, hotswapping the pages.

  • per_page (int) –

    The amount of pages to display per page. Defaults to 1.

    E,g: If per_page is 2 and pages is ["1", "2", "3", "4"], then the message will show ["1", "2"] on the first page and ["3", "4"] on the second page.

  • author_id (Optional[int]) – The id of the user who can interact with the paginator. Defaults to None.

  • check (Optional[Callable[[BaseClassPaginator, discord.Interaction], Union[bool, Coroutine[Any, Any, bool]]]]) –

    A callable that checks if the interaction is valid. This must be a callable that takes 2 or 3 parameters. The last two parameters represent the interaction and paginator respectively. It CAN be a coroutine.

    This is called in interaction_check().

    If author_id is not None, this won’t be called. Defaults to None.

  • always_allow_bot_owner (bool) – Whether to always allow the bot owner to interact with the paginator. Defaults to True.

  • delete_after (bool) – Whether to delete the message after the paginator stops. Only works if message is not None. Defaults to False.

  • disable_after (bool) – Whether to disable the paginator after the paginator stops. Only works if message is not None. Defaults to False.

  • clear_buttons_after (bool) – Whether to clear the buttons after the paginator stops. Only works if message is not None. Defaults to False.

  • message (Optional[discord.Message]) – The message to use for the paginator. This is set automatically when _send is called. Defaults to None.

  • add_page_string (bool) –

    Whether to add the page string to the page. Defaults to True. This is a string that represents the current page and the max pages. E,g: "Page 1 of 2".

    If the page is an embed, it will be appended to the footer text. If the page is a string, it will be appended to the string. else, it will be set as the content of the message.

  • timeout (Optional[Union[int, float]]) – The timeout for the paginator. Defaults to 180.0.

property current_page: int

The current page. Starts from 0.

Type:

int

async format_page(page)[source]

This method can be overridden to format the page before sending it. By default, it returns the page as is.

Parameters:

page (Union[Any], Sequence[Any]]) – The page to format.

Returns:

Union[Any], Sequence[Any]] – The formatted page(s).

Return type:

TypeAliasForwardRef(‘Any’) | Sequence[TypeAliasForwardRef(‘Any’)]

get_page(page_number)[source]

Gets the page with the given page number.

Parameters:

page_number (int) – The page number to get.

Returns:

Union[Any], Sequence[Any]] – The page(s) with the given page number.

Return type:

TypeAliasForwardRef(‘Any’) | Sequence[TypeAliasForwardRef(‘Any’)]

async get_page_kwargs(page, /, skip_formatting=False)[source]

Gets the kwargs to send the page with.

Parameters:
  • page (Union[Any, Sequence[Any]]) – The page to get the kwargs for.

  • skip_formatting (bool) – Whether to not call BaseClassPaginator.format_page() with the given page. Defaults to False.

Returns:

BaseKwargs – The kwargs to send the page with.

Return type:

BaseKwargs

async interaction_check(interaction)[source]

This method is called by the library when the paginator receives an interaction.

This method does the following checks (in order):

  • If always_allow_bot_owner is True, it checks if the interaction’s author id is one of the bot owners.

  • If author_id is not None, it checks if the interaction’s author id is the same as the one set.

  • If check is not None, it calls it and checks if it returns True.

  • If none of the above checks are True, it returns False.

Parameters:

interaction (discord.Interaction) – The interaction received.

Return type:

bool

property max_pages: int

The max pages of the paginator.

Type:

int

async on_page(interaction, before, after)[source]

Called when the paginator switches pages.

This method is called after the page is switched and does nothing by default.

Added in version 0.3.0.

Parameters:
  • interaction (discord.Interaction) – The interaction that triggered the event.

  • before (int) – The page number before.

  • after (int) – The page number after.

Return type:

None

async on_timeout()[source]

This method is called when the paginator times out.

This method does the following checks (in order):

Return type:

None

property page_string: str

A string representing the current page and the max pages.

Type:

str

property pages: Sequence[TypeAliasForwardRef('Any')]

The pages of the paginator.

Type:

Sequence[Any]

property per_page: int

The amount of pages to display per page.

Type:

int

async send(destination, *, override_page_kwargs=False, edit_message=False, **send_kwargs)[source]

Sends the message to the given destination.

Parameters:
  • destination (Union[discord.abc.Messageable, discord.Interaction]) – The destination to send the message to. Handles responding to the interaction if given.

  • override_page_kwargs (bool) – Whether to override the page kwargs with the given kwargs to send_kwargs. Defaults to False.

  • edit_message (bool) – Whether to edit the message instead of sending a new one. Defaults to False.

  • **send_kwargs (Any) – The kwargs to pass to the destination’s send method. Only used if override_page_kwargs is True.

Returns:

Optional[discord.Message] – The message or response sent.

Return type:

Message | None

stop()[source]

Stops the view and resets the base kwargs.

Return type:

None

async stop_paginator(interaction=None)[source]

Stops the paginator.

This method does handles deleting the message, disabling the paginator and clearing the buttons.

Parameters:

interaction (Optional[discord.Interaction]) – Optionally, the last interaction to edit. If None, .message is used.

Return type:

None

async switch_page(interaction, page_number)[source]

Switches the page to the given page number.

Parameters:
  • interaction (Optional[discord.Interaction]) – The interaction to edit. If None, .message is used.

  • page_number (int) – The page number to switch to.

Return type:

None