Skip to content

Commit 9f383c7

Browse files
NeloBlivionpre-commit-ci[bot]LulalabyJustaSqu1d
authored
feat: message forwarding (#2598)
* new message types * new embed type * implement types * update MessageReference * forwarding * style(pre-commit): auto fixes from pre-commit.com hooks * s * fix * style(pre-commit): auto fixes from pre-commit.com hooks * final? * fix import * style(pre-commit): auto fixes from pre-commit.com hooks * frfr * conflict 1 * style(pre-commit): auto fixes from pre-commit.com hooks * fix docstr * adjustments * style(pre-commit): auto fixes from pre-commit.com hooks * _get_message * fix reference kwarg * style(pre-commit): auto fixes from pre-commit.com hooks * undo * add system_content support * adjustments * style(pre-commit): auto fixes from pre-commit.com hooks * changelog * add has_snapshot flag * Apply suggestions from code review Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Lala Sabathil <aiko@aitsys.dev> * Update abc.py adjust wording --------- Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com> Signed-off-by: Lala Sabathil <aiko@aitsys.dev> Signed-off-by: Lala Sabathil <lala@pycord.dev> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil <aiko@aitsys.dev> Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Co-authored-by: Lala Sabathil <lala@pycord.dev>
1 parent faa9534 commit 9f383c7

File tree

9 files changed

+306
-21
lines changed

9 files changed

+306
-21
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ These changes are available on the `master` branch, but have not yet been releas
4949
([#2579](https://github.com/Pycord-Development/pycord/pull/2579))
5050
- Added new `Subscription` object and related methods/events.
5151
([#2564](https://github.com/Pycord-Development/pycord/pull/2564))
52+
- Added `Message.forward_to`, `Message.snapshots`, and other related attributes.
53+
([#2598](https://github.com/Pycord-Development/pycord/pull/2598))
5254
- Added the ability to change the API's base URL with `Route.API_BASE_URL`.
5355
([#2714](https://github.com/Pycord-Development/pycord/pull/2714))
5456
- Added the ability to pass a `datetime.time` object to `format_dt`

discord/abc.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -1497,9 +1497,9 @@ async def send(
14971497
.. versionadded:: 1.4
14981498
14991499
reference: Union[:class:`~discord.Message`, :class:`~discord.MessageReference`, :class:`~discord.PartialMessage`]
1500-
A reference to the :class:`~discord.Message` to which you are replying, this can be created using
1501-
:meth:`~discord.Message.to_reference` or passed directly as a :class:`~discord.Message`. You can control
1502-
whether this mentions the author of the referenced message using the
1500+
A reference to the :class:`~discord.Message` being replied to or forwarded. This can be created using
1501+
:meth:`~discord.Message.to_reference`.
1502+
When replying, you can control whether this mentions the author of the referenced message using the
15031503
:attr:`~discord.AllowedMentions.replied_user` attribute of ``allowed_mentions`` or by
15041504
setting ``mention_author``.
15051505
@@ -1589,9 +1589,19 @@ async def send(
15891589
allowed_mentions = allowed_mentions or AllowedMentions().to_dict()
15901590
allowed_mentions["replied_user"] = bool(mention_author)
15911591

1592+
_reference = None
15921593
if reference is not None:
15931594
try:
1594-
reference = reference.to_message_reference_dict()
1595+
_reference = reference.to_message_reference_dict()
1596+
from .message import MessageReference
1597+
1598+
if not isinstance(reference, MessageReference):
1599+
utils.warn_deprecated(
1600+
f"Passing {type(reference).__name__} to reference",
1601+
"MessageReference",
1602+
"2.7",
1603+
"3.0",
1604+
)
15951605
except AttributeError:
15961606
raise InvalidArgument(
15971607
"reference parameter must be Message, MessageReference, or"
@@ -1641,7 +1651,7 @@ async def send(
16411651
nonce=nonce,
16421652
enforce_nonce=enforce_nonce,
16431653
allowed_mentions=allowed_mentions,
1644-
message_reference=reference,
1654+
message_reference=_reference,
16451655
stickers=stickers,
16461656
components=components,
16471657
flags=flags.value,
@@ -1660,7 +1670,7 @@ async def send(
16601670
nonce=nonce,
16611671
enforce_nonce=enforce_nonce,
16621672
allowed_mentions=allowed_mentions,
1663-
message_reference=reference,
1673+
message_reference=_reference,
16641674
stickers=stickers,
16651675
components=components,
16661676
flags=flags.value,

discord/channel.py

+3
Original file line numberDiff line numberDiff line change
@@ -3412,6 +3412,9 @@ def get_partial_message(self, message_id: int, /) -> PartialMessage:
34123412

34133413
return PartialMessage(channel=self, id=message_id)
34143414

3415+
def __repr__(self) -> str:
3416+
return f"<PartialMessageable id={self.id} type={self.type!r}>"
3417+
34153418

34163419
def _guild_channel_factory(channel_type: int):
34173420
value = try_enum(ChannelType, channel_type)

discord/enums.py

+15
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
"EntitlementOwnerType",
7777
"IntegrationType",
7878
"InteractionContextType",
79+
"PollLayoutType",
80+
"MessageReferenceType",
7981
)
8082

8183

@@ -266,6 +268,12 @@ class MessageType(Enum):
266268
stage_raise_hand = 30
267269
stage_topic = 31
268270
guild_application_premium_subscription = 32
271+
guild_incident_alert_mode_enabled = 36
272+
guild_incident_alert_mode_disabled = 37
273+
guild_incident_report_raid = 38
274+
guild_incident_report_false_alarm = 39
275+
purchase_notification = 44
276+
poll_result = 46
269277

270278

271279
class VoiceRegion(Enum):
@@ -1055,6 +1063,13 @@ class PollLayoutType(Enum):
10551063
default = 1
10561064

10571065

1066+
class MessageReferenceType(Enum):
1067+
"""The type of the message reference object"""
1068+
1069+
default = 0
1070+
forward = 1
1071+
1072+
10581073
class SubscriptionStatus(Enum):
10591074
"""The status of a subscription."""
10601075

discord/ext/commands/context.py

+6
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,9 @@ async def send_help(self, *args: Any) -> Any:
403403
@discord.utils.copy_doc(Message.reply)
404404
async def reply(self, content: str | None = None, **kwargs: Any) -> Message:
405405
return await self.message.reply(content, **kwargs)
406+
407+
@discord.utils.copy_doc(Message.forward_to)
408+
async def forward_to(
409+
self, channel: discord.abc.Messageable, **kwargs: Any
410+
) -> Message:
411+
return await self.message.forward_to(channel, **kwargs)

discord/flags.py

+8
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,14 @@ def is_voice_message(self):
411411
"""
412412
return 8192
413413

414+
@flag_value
415+
def has_snapshot(self):
416+
""":class:`bool`: Returns ``True`` if this message has a snapshot from message forwarding.
417+
418+
.. versionadded:: 2.7
419+
"""
420+
return 1 << 14
421+
414422

415423
@fill_with_flags()
416424
class PublicUserFlags(BaseFlags):

0 commit comments

Comments
 (0)