Paginators¶
See here the various paginators available in this package.
Selects¶
- class discord.ext.paginators.select_paginator.SelectOptionsPaginator(pages, *, per_select=..., set_default_on_switch=True, set_default_on_select=True, add_in_order=False, default_option=None, **kwargs)[source]¶
Bases:
BaseClassPaginator[PageT]A paginator that uses discord.ui.Select to select pages.
This paginator provides one select and two buttons to navigate through “pages” with options.
Just for clarification, here is a list of supported pages:
PaginatorOption(a subclass ofdiscord.SelectOptionwith acontentkwarg that can be any of the above)
Other parameters are the same as
discord.ext.paginators.base_paginator.BaseClassPaginator. Exceptper_pagewhich is always1and cannot be changed.- Parameters:
pages (Sequence[Union[Any,
PaginatorOption]]) –A sequence of pages to paginate through. A page can be anything that is supported by the
BaseClassPaginatorclass. With the addition ofPaginatorOptionwhich is a subclass ofdiscord.SelectOptionthat also contains acontentattribute, it can be used to provide a custom label, description and emoji for each “page”.All options will be split into chunks of
per_selectand each chunk will be a select. IF a chunk is a already a list, it will be treated as a single select. If this chunk contains less or more items thanper_select, it will raise a ValueError.Example:
pages = [ # This will be a single select with 3 options # per_select must be >= 3 or it will raise a ValueError ["Page 1", "Page 2", "Page 3"], # These will span across the needed amount of selects "Page 4", "Page 5", "Page 6", "Page 7", ... ]
Note that a nested list ([1, 2, 3, [4, 5, 6]]) is not supported.
per_select (Optional[
int]) – The amount of options per select. Defaults toSelectOptionsPaginator.MAX_SELECT_OPTIONS.add_in_order (
bool) –Whether to add the options in the order they are provided. Defaults to
False.Falsewill add the option in whatever order the library parses them.Example
1# if True 2pages = [ 3 | <page 1>, | 4 | <page 2>, | 5 | <page 3>, | 6 # this ^ will be a single select with 3 options 7 [<page 4>, <page 5>, <page 6>, <page 7>], 8 # this ^ will be a single select with 4 options 9 | <page 7>, | 10 # this ^ will be a single select with 1 option 11 [<page 8>, <page 9>, <page 10>], 12 # this ^ will be a single select with 3 options 13 ... 14 # and so on 15] 16 17# if False 18pages = [ 19 <page 1>, 20 <page 2>, 21 <page 3>, 22 [<page 4>, <page 5>, <page 6>, <page 7>], 23 # this ^ will be a single select with 4 options 24 <page 7>, 25 [<page 8>, <page 9>, <page 10>], 26 # this ^ will be a single select with 3 options 27 ... 28 # and so on 29 30 # pages 1, 2, 3 and 7 will be in one select. 31]
Make sure to experiment with this to see what fits your needs the best.
Added in version 0.3.0.
set_default_on_switch (
bool) –Whether to set the first option of each “page” as the default option.
This is also used when sending the paginator for the first time.
Defaults to
True.Added in version 0.3.0.
set_default_on_select (
bool) –Whether to set the selected option as the default option. Defaults to
True.Added in version 0.3.0.
default_option (Optional[
discord.SelectOption]) –The option to get the metadata from if the a page is not an instance of
PaginatorOption. If this isNone, it will try to get the metadata from the page itself. E,g if the page is an embed, it will try to get the title or description, etc and use that as the label.Defaults to
None.Deprecated since version 0.3.0: This parameter is deprecated and will be removed in a future version. It is recommended to use
PaginatorOptioninstead.kwargs (
Unpack[BasePaginatorKwargs[Self]])
- MAX_SELECT_OPTIONS: ClassVar[Literal[25]] = 25¶
The maximum amount of options per select by discord by the time of writing this.
- async format_page(page)[source]¶
This method can be overridden to format the page before sending it. By default, it returns the page’s content.
- Parameters:
page (
PaginatorOption) –The option to format.
Use the
contentattribute to get the contents of the page.Changed in version 0.3.0: This is now the selected option instead of the page’s contents.
- 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:
PaginatorOption[TypeAliasForwardRef(‘Any’)]
- async on_select(interaction, option)[source]¶
This method is called when an option is selected.
This method can be overridden to provide custom behavior when an option is selected. This method is called after the select is updated and does nothing by default.
Added in version 0.3.0.
- Parameters:
interaction (
discord.Interaction) – The interaction that triggered the select.option (
PaginatorOption) – The selected option.
- Return type:
None
- class discord.ext.paginators.select_paginator.PaginatorOption(content, *, label=..., emoji=None, value=..., description=None)[source]¶
Bases:
SelectOption,Generic[PageT]A subclass of
discord.SelectOptionrepresenting a page in aSelectOptionsPaginator.Other parameters are the same as
SelectOption.- Parameters:
content (Union[Any, Sequence[Any]]) – The content of the page. See
SelectOptionsPaginatorfor more the supported types.emoji (Optional[Union[
str,discord.Emoji,discord.PartialEmoji]]) – The emoji to use for the option. Defaults toNone.label (
str(default:...))value (
str(default:...))