API Reference
Contents
API Reference#
Contents
Page Sources#
PageSource (Basic Interface)#
- asyncformat_page
- defget_max_pages
- asyncget_page
- defis_paginating
- asyncprepare
An interface representing a menu page’s data source for the actual menu page.
Subclasses must implement the backing resource along with the following methods:
This function could be a coroutine.
An abstract method to format the page.
This method must return one of the following types.
If this method returns a
str
then it is interpreted as returning thecontent
keyword argument innextcord.Message.edit()
andnextcord.abc.Messageable.send()
.If this method returns a
nextcord.Embed
then it is interpreted as returning theembed
keyword argument innextcord.Message.edit()
andnextcord.abc.Messageable.send()
.If this method returns a List[
nextcord.Embed
] then it is interpreted as returning theembeds
keyword argument innextcord.Message.edit()
andnextcord.abc.Messageable.send()
.If this method returns a
dict
then it is interpreted as the keyword-arguments that are used in bothnextcord.Message.edit()
andnextcord.abc.Messageable.send()
. A few of interest are:content
,embed
,embeds
,file
,files
.- Parameters
menu (
Menu
) – The menu that wants to format this page.page (Any) – The page returned by
get_page()
.
- Returns
See above.
- Return type
Union[
str
,nextcord.Embed
, List[nextcord.Embed
],dict
]
An optional abstract method that retrieves the maximum number of pages this page source has. Useful for UX purposes.
The default implementation returns
None
.- Returns
The maximum number of pages required to properly paginate the elements, if given.
- Return type
Optional[
int
]
This function is a coroutine.
An abstract method that retrieves an object representing the object to format.
Subclasses must implement this.
Note
The page_number is zero-indexed between [0,
get_max_pages()
), if there is a maximum number of pages.- Parameters
page_number (
int
) – The page number to access.- Returns
The object represented by that page. This is passed into
format_page()
.- Return type
Any
An abstract method that notifies the
MenuPagesBase
whether or not to start paginating.This signals whether to add menus to this page source. Menus can either be buttons or reactions depending on the subclass.
Subclasses must implement this.
- Returns
Whether to trigger pagination.
- Return type
This function is a coroutine.
A coroutine that is called after initialisation but before anything else to do some asynchronous set up as well as the one provided in
__init__
.By default this does nothing.
This coroutine will only be called once.
ListPageSource#
- asyncformat_page
- defget_max_pages
- asyncget_page
- defis_paginating
- asyncprepare
A data source for a sequence of items.
This page source does not handle any sort of formatting, leaving it up to the user. To do so, implement the
format_page()
method.The sequence of items to paginate.
- Type
Sequence[Any]
How many elements are in a page.
- Type
An abstract method to format the page.
This works similar to the
PageSource.format_page()
except the type of thepage
parameter is documented.- Parameters
menu (
Menu
) – The menu that wants to format this page.page (Union[Any, List[Any]]) – The page returned by
get_page()
. This is either a single element ifper_page
is set to1
or a slice of the sequence otherwise.
- Returns
- Return type
Union[
str
,nextcord.Embed
, List[nextcord.Embed
],dict
]
int
: The maximum number of pages required to paginate this sequence.
Returns either a single element of the sequence or a slice of the sequence.
If
per_page
is set to1
then this returns a single element. Otherwise it returns at mostper_page
elements.- Returns
The data returned.
- Return type
Union[Any, Sequence[Any]]
bool
: Whether pagination is required.
This function is a coroutine.
A coroutine that is called after initialisation but before anything else to do some asynchronous set up as well as the one provided in
__init__
.By default this does nothing.
This coroutine will only be called once.
GroupByPageSource#
- asyncformat_page
- defget_max_pages
- asyncget_page
- defis_paginating
- asyncprepare
A data source for grouped by sequence of items.
This inherits from
ListPageSource
.This page source does not handle any sort of formatting, leaving it up to the user. To do so, implement the
format_page()
method.- Parameters
entries (Sequence[Any]) – The sequence of items to paginate and group.
key (Callable[[Any], Any]) – A key function to do the grouping with.
sort (
bool
) – Whether to sort the sequence before grouping it. The elements are sorted according to thekey
function passed.per_page (
int
) – How many elements to have per page of the group.
The sequence of items to paginate.
- Type
Sequence[Any]
How many elements are in a page.
- Type
An abstract method to format the page.
This works similar to the
PageSource.format_page()
except the type of theentry
parameter is documented.- Parameters
menu (
Menu
) – The menu that wants to format this page.entry (GroupByEntry) – The page returned by
get_page()
. This will be aGroupByEntry
withkey
, representing the key of theitertools.groupby()
function, anditems
, representing a sequence of paginated items within that group.
- Returns
- Return type
Union[
str
,nextcord.Embed
, List[nextcord.Embed
],dict
]
int
: The maximum number of pages required to paginate this sequence.
Returns a
GroupByEntry
withkey
, representing the key of theitertools.groupby()
function, anditems
, representing a sequence of paginated items within that group.- Returns
The data returned.
- Return type
bool
: Whether pagination is required.
This function is a coroutine.
A coroutine that is called after initialisation but before anything else to do some asynchronous set up as well as the one provided in
__init__
.By default this does nothing.
This coroutine will only be called once.
GroupByEntry#
Named tuple representing an entry returned by
GroupByPageSource.get_page()
in aGroupByPageSource
.A key of the
itertools.groupby()
function.- Type
Callable[[Any], Any]
Slice of the paginated items within the group.
- Type
List[Any]
AsyncIteratorPageSource#
- asyncformat_page
- defget_max_pages
- asyncget_page
- defis_paginating
- asyncprepare
A data source for data backed by an asynchronous iterator.
This page source does not handle any sort of formatting, leaving it up to the user. To do so, implement the
format_page()
method.- Parameters
iterator (AsyncIterator[Any]) – The asynchronous iterator to paginate.
per_page (
int
) – How many elements to have per page.
The async iterator of items to paginate.
- Type
AsyncIterator[Any]
How many elements are in a page.
- Type
An abstract method to format the page.
This works similar to the
PageSource.format_page()
except the type of thepage
parameter is documented.- Parameters
menu (
Menu
) – The menu that wants to format this page.page (Union[Any, List[Any]]) – The page returned by
get_page()
. This is either a single element ifper_page
is set to1
or a slice of the sequence otherwise.
- Returns
- Return type
Union[
str
,nextcord.Embed
, List[nextcord.Embed
],dict
]
An optional abstract method that retrieves the maximum number of pages this page source has. Useful for UX purposes.
The default implementation returns
None
.- Returns
The maximum number of pages required to properly paginate the elements, if given.
- Return type
Optional[
int
]
Returns either a single element of the sequence or a slice of the sequence.
If
per_page
is set to1
then this returns a single element. Otherwise it returns at mostper_page
elements.- Returns
The data returned.
- Return type
Union[Any, List[Any]]
bool
: Whether pagination is required.
This function is a coroutine.
A coroutine that is called after initialisation but before anything else to do some asynchronous set up as well as the one provided in
__init__
.By default this does nothing.
This coroutine will only be called once.
Exceptions#
CannotEmbedLinks#
Exception for when the bot is unable to embed links
CannotSendMessages#
Exception for when the bot is unable to send messages
CannotAddReactions#
Exception for when the bot is unable to add reactions
CannotReadMessageHistory#
Exception for when the bot is unable to read message history