Skip to content
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

Add reference, allowed_mentions, and mention_author parameters to Paginator.send() #1097

Merged
merged 1 commit into from
Mar 1, 2022
Merged
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
38 changes: 37 additions & 1 deletion discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ async def send(
ctx: Context,
target: Optional[discord.abc.Messageable] = None,
target_message: Optional[str] = None,
reference: Optional[Union[discord.Message, discord.MessageReference, discord.PartialMessage]] = None,
allowed_mentions: Optional[discord.AllowedMentions] = None,
mention_author: bool = None,
) -> discord.Message:
"""Sends a message with the paginated items.

Expand All @@ -616,6 +619,20 @@ async def send(
A target where the paginated message should be sent, if different from the original :class:`Context`
target_message: Optional[:class:`str`]
An optional message shown when the paginator message is sent elsewhere.
reference: Optional[Union[:class:`discord.Message`, :class:`discord.MessageReference`, :class:`discord.PartialMessage`]]
A reference to the :class:`~discord.Message` to which you are replying with the paginator. This can be created using
:meth:`~discord.Message.to_reference` or passed directly as a :class:`~discord.Message`. You can control
whether this mentions the author of the referenced message using the :attr:`~discord.AllowedMentions.replied_user`
attribute of ``allowed_mentions`` or by setting ``mention_author``.
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.
mention_author: Optional[:class:`bool`]
If set, overrides the :attr:`~discord.AllowedMentions.replied_user` attribute of ``allowed_mentions``.

Returns
--------
Expand All @@ -628,6 +645,17 @@ async def send(
if target is not None and not isinstance(target, discord.abc.Messageable):
raise TypeError(f"expected abc.Messageable not {target.__class__!r}")

if reference is not None and not isinstance(
reference, (discord.Message, discord.MessageReference, discord.PartialMessage)
):
raise TypeError(f"expected Message, MessageReference, or PartialMessage not {reference.__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}")

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

self.update_buttons()
page = self.pages[self.current_page]
page = self.get_page_content(page)
Expand All @@ -636,13 +664,21 @@ async def send(

if target:
if target_message:
await ctx.send(target_message)
await ctx.send(
target_message,
reference=reference,
allowed_mentions=allowed_mentions,
mention_author=mention_author,
)
ctx = target

self.message = await ctx.send(
content=page if isinstance(page, str) else None,
embeds=[] if isinstance(page, str) else page,
view=self,
reference=reference,
allowed_mentions=allowed_mentions,
mention_author=mention_author,
)

return self.message
Expand Down