Skip to content

Commit d71dc94

Browse files
committed
feat: add channel_send method
1 parent f75b7f1 commit d71dc94

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

discord/ext/pages/pagination.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,61 @@ async def send(
10461046

10471047
return self.message
10481048

1049+
async def channel_send(
1050+
self,
1051+
channel: discord.abc.Messageable,
1052+
allowed_mentions: discord.AllowedMentions | None = None,
1053+
delete_after: float | None = None,
1054+
) -> discord.Message:
1055+
"""Sends a message to a specified channel with the paginated items.
1056+
1057+
Parameters
1058+
----------
1059+
channel: Optional[:class:`~discord.abc.Messageable`]
1060+
A channel where the paginated message should be sent.
1061+
allowed_mentions: Optional[:class:`~discord.AllowedMentions`]
1062+
Controls the mentions being processed in this message. If this is
1063+
passed, then the object is merged with :attr:`~discord.Client.allowed_mentions`.
1064+
The merging behaviour only overrides attributes that have been explicitly passed
1065+
to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
1066+
If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
1067+
are used instead.
1068+
delete_after: Optional[:class:`float`]
1069+
If set, deletes the paginator after the specified time.
1070+
1071+
Returns
1072+
-------
1073+
:class:`~discord.Message`
1074+
The message that was sent with the paginator.
1075+
"""
1076+
if not isinstance(channel, discord.abc.Messageable):
1077+
raise TypeError(f"expected abc.Messageable not {channel.__class__!r}")
1078+
1079+
if allowed_mentions is not None and not isinstance(
1080+
allowed_mentions, discord.AllowedMentions
1081+
):
1082+
raise TypeError(
1083+
f"expected AllowedMentions not {allowed_mentions.__class__!r}"
1084+
)
1085+
1086+
self.update_buttons()
1087+
page = self.pages[self.current_page]
1088+
page_content = self.get_page_content(page)
1089+
1090+
if page_content.custom_view:
1091+
self.update_custom_view(page_content.custom_view)
1092+
1093+
self.message = await channel.send(
1094+
content=page_content.content,
1095+
embeds=page_content.embeds,
1096+
files=page_content.files,
1097+
view=self,
1098+
allowed_mentions=allowed_mentions,
1099+
delete_after=delete_after,
1100+
)
1101+
1102+
return self.message
1103+
10491104
async def edit(
10501105
self,
10511106
message: discord.Message,

0 commit comments

Comments
 (0)