Skip to content

Commit 4514fe1

Browse files
authored
add reference, allowed_mentions, and mention_author parameters to paginator.send to allow controlling the underlying Messageable.send() behavior. (#1097)
1 parent 81d7632 commit 4514fe1

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

discord/ext/pages/pagination.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ async def send(
605605
ctx: Context,
606606
target: Optional[discord.abc.Messageable] = None,
607607
target_message: Optional[str] = None,
608+
reference: Optional[Union[discord.Message, discord.MessageReference, discord.PartialMessage]] = None,
609+
allowed_mentions: Optional[discord.AllowedMentions] = None,
610+
mention_author: bool = None,
608611
) -> discord.Message:
609612
"""Sends a message with the paginated items.
610613
@@ -616,6 +619,20 @@ async def send(
616619
A target where the paginated message should be sent, if different from the original :class:`Context`
617620
target_message: Optional[:class:`str`]
618621
An optional message shown when the paginator message is sent elsewhere.
622+
reference: Optional[Union[:class:`discord.Message`, :class:`discord.MessageReference`, :class:`discord.PartialMessage`]]
623+
A reference to the :class:`~discord.Message` to which you are replying with the paginator. This can be created using
624+
:meth:`~discord.Message.to_reference` or passed directly as a :class:`~discord.Message`. You can control
625+
whether this mentions the author of the referenced message using the :attr:`~discord.AllowedMentions.replied_user`
626+
attribute of ``allowed_mentions`` or by setting ``mention_author``.
627+
allowed_mentions: Optional[:class:`~discord.AllowedMentions`]
628+
Controls the mentions being processed in this message. If this is
629+
passed, then the object is merged with :attr:`~discord.Client.allowed_mentions`.
630+
The merging behaviour only overrides attributes that have been explicitly passed
631+
to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
632+
If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
633+
are used instead.
634+
mention_author: Optional[:class:`bool`]
635+
If set, overrides the :attr:`~discord.AllowedMentions.replied_user` attribute of ``allowed_mentions``.
619636
620637
Returns
621638
--------
@@ -628,6 +645,17 @@ async def send(
628645
if target is not None and not isinstance(target, discord.abc.Messageable):
629646
raise TypeError(f"expected abc.Messageable not {target.__class__!r}")
630647

648+
if reference is not None and not isinstance(
649+
reference, (discord.Message, discord.MessageReference, discord.PartialMessage)
650+
):
651+
raise TypeError(f"expected Message, MessageReference, or PartialMessage not {reference.__class__!r}")
652+
653+
if allowed_mentions is not None and not isinstance(allowed_mentions, discord.AllowedMentions):
654+
raise TypeError(f"expected AllowedMentions not {allowed_mentions.__class__!r}")
655+
656+
if mention_author is not None and not isinstance(mention_author, bool):
657+
raise TypeError(f"expected bool not {mention_author.__class__!r}")
658+
631659
self.update_buttons()
632660
page = self.pages[self.current_page]
633661
page = self.get_page_content(page)
@@ -636,13 +664,21 @@ async def send(
636664

637665
if target:
638666
if target_message:
639-
await ctx.send(target_message)
667+
await ctx.send(
668+
target_message,
669+
reference=reference,
670+
allowed_mentions=allowed_mentions,
671+
mention_author=mention_author,
672+
)
640673
ctx = target
641674

642675
self.message = await ctx.send(
643676
content=page if isinstance(page, str) else None,
644677
embeds=[] if isinstance(page, str) else page,
645678
view=self,
679+
reference=reference,
680+
allowed_mentions=allowed_mentions,
681+
mention_author=mention_author,
646682
)
647683

648684
return self.message

0 commit comments

Comments
 (0)