Skip to content

feat: Add method to send paginator to channel outside context of user interaction #2713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2579](https://github.com/Pycord-Development/pycord/pull/2579))
- Added new `Subscription` object and related methods/events.
([#2564](https://github.com/Pycord-Development/pycord/pull/2564))
- Added `Paginator.channel_send` method for sending paginators without user context.
([#2713](https://github.com/Pycord-Development/pycord/pull/2713))

### Fixed

Expand Down
55 changes: 55 additions & 0 deletions discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,61 @@ async def send(

return self.message

async def channel_send(
self,
channel: discord.abc.Messageable,
allowed_mentions: discord.AllowedMentions | None = None,
delete_after: float | None = None,
) -> discord.Message:
"""Sends a message to a specified channel with the paginated items.

Parameters
----------
channel: Optional[:class:`~discord.abc.Messageable`]
A channel where the paginated message should be sent.
allowed_mentions: Optional[:class:`~discord.AllowedMentions`]
Controls the mentions being processed in this message. If this is
passed, then the object is merged with :attr:`~discord.Client.allowed_mentions`.
The merging behaviour only overrides attributes that have been explicitly passed
to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
are used instead.
delete_after: Optional[:class:`float`]
If set, deletes the paginator after the specified time.

Returns
-------
:class:`~discord.Message`
The message that was sent with the paginator.
"""
if not isinstance(channel, discord.abc.Messageable):
raise TypeError(f"expected abc.Messageable not {channel.__class__!r}")

if allowed_mentions is not None and not isinstance(
allowed_mentions, discord.AllowedMentions
):
raise TypeError(
f"expected AllowedMentions not {allowed_mentions.__class__!r}"
)

self.update_buttons()
page = self.pages[self.current_page]
page_content = self.get_page_content(page)

if page_content.custom_view:
self.update_custom_view(page_content.custom_view)

self.message = await channel.send(
content=page_content.content,
embeds=page_content.embeds,
files=page_content.files,
view=self,
allowed_mentions=allowed_mentions,
delete_after=delete_after,
)

return self.message

async def edit(
self,
message: discord.Message,
Expand Down
Loading