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: Callsto_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_pageis2andpagesis["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 toNone.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_idis notNone, this won’t be called. Defaults toNone.always_allow_bot_owner (
bool) – Whether to always allow the bot owner to interact with the paginator. Defaults toTrue.delete_after (
bool) – Whether to delete the message after the paginator stops. Only works ifmessageis notNone. Defaults toFalse.disable_after (
bool) – Whether to disable the paginator after the paginator stops. Only works ifmessageis notNone. Defaults toFalse.clear_buttons_after (
bool) – Whether to clear the buttons after the paginator stops. Only works ifmessageis notNone. Defaults toFalse.message (Optional[
discord.Message]) – The message to use for the paginator. This is set automatically when_sendis called. Defaults toNone.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 to180.0.
- 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’)]
- 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 toFalse.
- Returns:
BaseKwargs– The kwargs to send the page with.- Return type:
- 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_ownerisTrue, it checks if the interaction’s author id is one of the bot owners.If
author_idis notNone, it checks if the interaction’s author id is the same as the one set.If
checkis notNone, it calls it and checks if it returnsTrue.If none of the above checks are
True, it returnsFalse.
- Parameters:
interaction (
discord.Interaction) – The interaction received.- Return type:
- 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 pages: Sequence[TypeAliasForwardRef('Any')]¶
The pages of the paginator.
- Type:
Sequence[Any]
- 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 tosend_kwargs. Defaults toFalse.edit_message (
bool) – Whether to edit the message instead of sending a new one. Defaults toFalse.**send_kwargs (Any) – The kwargs to pass to the destination’s send method. Only used if
override_page_kwargsisTrue.
- Returns:
Optional[
discord.Message] – The message or response sent.- Return type:
Message | 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. IfNone,.messageis 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. IfNone,.messageis used.page_number (
int) – The page number to switch to.
- Return type:
None