Skip to content

Commit

Permalink
feat(message): implement message forwarding (#1188)
Browse files Browse the repository at this point in the history
Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]>
  • Loading branch information
Snipy7374 and shiftinv authored Dec 11, 2024
1 parent 2dab45c commit 08b2bea
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog/1187.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for message forwarding. New :class:`ForwardedMessage`, new enum :class:`MessageReferenceType`, new method :func:`Message.forward`, edited :class:`MessageReference` to support message forwarding.
6 changes: 6 additions & 0 deletions disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,12 @@ async def send(
.. versionadded:: 1.6
.. note::
Passing a :class:`.Message` or :class:`.PartialMessage` will only allow replies. To forward a message
you must explicitly transform the message to a :class:`.MessageReference` using :meth:`.Message.to_reference` and specify the :class:`.MessageReferenceType`,
or use :meth:`.Message.forward`.
mention_author: Optional[:class:`bool`]
If set, overrides the :attr:`.AllowedMentions.replied_user` attribute of ``allowed_mentions``.
Expand Down
8 changes: 8 additions & 0 deletions disnake/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"EntitlementType",
"PollLayoutType",
"VoiceChannelEffectAnimationType",
"MessageReferenceType",
)


Expand Down Expand Up @@ -1415,6 +1416,13 @@ class VoiceChannelEffectAnimationType(Enum):
basic = 1


class MessageReferenceType(Enum):
default = 0
"""A standard message reference used in message replies."""
forward = 1
"""Reference used to point to a message at a point in time (forward)."""


T = TypeVar("T")


Expand Down
11 changes: 11 additions & 0 deletions disnake/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ def __init__(
crossposted: bool = ...,
ephemeral: bool = ...,
failed_to_mention_roles_in_thread: bool = ...,
has_snapshot: bool = ...,
has_thread: bool = ...,
is_crossposted: bool = ...,
is_voice_message: bool = ...,
Expand Down Expand Up @@ -692,6 +693,16 @@ def is_voice_message(self):
"""
return 1 << 13

@flag_value
def has_snapshot(self):
""":class:`bool`: Returns ``True`` if the message is a forward message.
Messages with this flag will have only the forward data, and no other content.
.. versionadded:: 2.10
"""
return 1 << 14


class PublicUserFlags(BaseFlags):
"""Wraps up the Discord User Public flags.
Expand Down
8 changes: 6 additions & 2 deletions disnake/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,15 @@ def _update_from_message(self, data: MemberPayload) -> None:

@classmethod
def _try_upgrade(
cls, *, data: UserWithMemberPayload, guild: Guild, state: ConnectionState
cls,
*,
data: Union[UserPayload, UserWithMemberPayload],
guild: Guild,
state: ConnectionState,
) -> Union[User, Self]:
# A User object with a 'member' key
try:
member_data = data.pop("member")
member_data = data.pop("member") # type: ignore
except KeyError:
return state.create_user(data)
else:
Expand Down
Loading

0 comments on commit 08b2bea

Please sign in to comment.