Skip to content

feat: message forwarding #2598

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 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7fb97fb
new message types
NeloBlivion Oct 6, 2024
58e7c6c
new embed type
NeloBlivion Oct 6, 2024
901bdfe
implement types
NeloBlivion Oct 6, 2024
ceaffaf
update MessageReference
NeloBlivion Oct 6, 2024
5baa513
forwarding
NeloBlivion Oct 6, 2024
8c0a3ee
Merge branch 'master' into forwarding
NeloBlivion Oct 6, 2024
b64ec06
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2024
c99efe6
s
NeloBlivion Oct 6, 2024
dde7436
fix
NeloBlivion Oct 6, 2024
ea21897
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2024
3f6be75
final?
NeloBlivion Oct 6, 2024
cd632c3
fix import
NeloBlivion Oct 6, 2024
7454697
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2024
4bb20d8
frfr
NeloBlivion Oct 6, 2024
7bbfd96
Merge branch 'master' into forwarding
NeloBlivion Oct 14, 2024
2e1c15a
Merge branch 'master' into forwarding
NeloBlivion Nov 6, 2024
e1cfad7
Merge branch 'master' into forwarding
NeloBlivion Nov 17, 2024
c7da3b8
conflict 1
NeloBlivion Feb 4, 2025
2d33242
Merge branch 'master' into forwarding
NeloBlivion Feb 4, 2025
a4657da
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2025
1d6b0bf
fix docstr
NeloBlivion Feb 4, 2025
acd29ef
adjustments
NeloBlivion Feb 5, 2025
ac39fc3
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 5, 2025
63f1675
_get_message
NeloBlivion Feb 5, 2025
389ffa7
fix reference kwarg
NeloBlivion Feb 5, 2025
0d49197
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 5, 2025
579751a
undo
NeloBlivion Feb 5, 2025
95474f8
add system_content support
NeloBlivion Feb 5, 2025
39652ab
adjustments
NeloBlivion Feb 5, 2025
8879fd6
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 5, 2025
01ef32e
changelog
NeloBlivion Feb 6, 2025
21c0e59
Merge branch 'master' into forwarding
NeloBlivion Feb 6, 2025
cf98e47
add has_snapshot flag
NeloBlivion Feb 6, 2025
9a115b1
Merge branch 'master' into forwarding
NeloBlivion Feb 7, 2025
6e50f4e
Merge branch 'master' into forwarding
NeloBlivion Feb 16, 2025
cba053d
Merge branch 'master' into forwarding
NeloBlivion Feb 28, 2025
b78152a
Apply suggestions from code review
Lulalaby Mar 27, 2025
e4716ae
Merge branch 'master' into forwarding
Lulalaby Mar 27, 2025
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 `Message.forward_to`, `Message.snapshots` and related attributes.
([#2598](https://github.com/Pycord-Development/pycord/pull/2598))
- Added ability to change the API's base URL with `Route.API_BASE_URL`.
([#2714](https://github.com/Pycord-Development/pycord/pull/2714))

Expand Down
20 changes: 15 additions & 5 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,8 +1493,8 @@ async def send(
.. versionadded:: 1.4

reference: Union[:class:`~discord.Message`, :class:`~discord.MessageReference`, :class:`~discord.PartialMessage`]
A reference to the :class:`~discord.Message` to which you are replying, this can be created using
:meth:`~discord.Message.to_reference` or passed directly as a :class:`~discord.Message`. You can control
A reference to the :class:`~discord.Message` you are replying to or forwarding, this can be created using
:meth:`~discord.Message.to_reference` or passed directly as a :class:`~discord.Message`. When replying, you can control
Comment on lines +1500 to +1501
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A reference to the :class:`~discord.Message` you are replying to or forwarding, this can be created using
:meth:`~discord.Message.to_reference` or passed directly as a :class:`~discord.Message`. When replying, you can control
A reference to the :class:`~discord.Message` you are replying to or forwarding, this can be created using
:meth:`~discord.Message.to_reference` or passed directly as a :class:`~discord.Message`. When replying, you can control

Two things here

  • this is a run-on sentence. Please reword and fix.
  • "you" is too casual and the sentence should be reworded in passive voice.

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``.
Expand Down Expand Up @@ -1585,9 +1585,19 @@ async def send(
allowed_mentions = allowed_mentions or AllowedMentions().to_dict()
allowed_mentions["replied_user"] = bool(mention_author)

_reference = None
if reference is not None:
try:
reference = reference.to_message_reference_dict()
_reference = reference.to_message_reference_dict()
from .message import MessageReference

if not isinstance(reference, MessageReference):
utils.warn_deprecated(
f"Passing {type(reference).__name__} to reference",
"MessageReference",
"2.7",
"3.0",
)
except AttributeError:
raise InvalidArgument(
"reference parameter must be Message, MessageReference, or"
Expand Down Expand Up @@ -1637,7 +1647,7 @@ async def send(
nonce=nonce,
enforce_nonce=enforce_nonce,
allowed_mentions=allowed_mentions,
message_reference=reference,
message_reference=_reference,
stickers=stickers,
components=components,
flags=flags.value,
Expand All @@ -1656,7 +1666,7 @@ async def send(
nonce=nonce,
enforce_nonce=enforce_nonce,
allowed_mentions=allowed_mentions,
message_reference=reference,
message_reference=_reference,
stickers=stickers,
components=components,
flags=flags.value,
Expand Down
3 changes: 3 additions & 0 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3412,6 +3412,9 @@ def get_partial_message(self, message_id: int, /) -> PartialMessage:

return PartialMessage(channel=self, id=message_id)

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


def _guild_channel_factory(channel_type: int):
value = try_enum(ChannelType, channel_type)
Expand Down
15 changes: 15 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"EntitlementOwnerType",
"IntegrationType",
"InteractionContextType",
"PollLayoutType",
"MessageReferenceType",
)


Expand Down Expand Up @@ -266,6 +268,12 @@ class MessageType(Enum):
stage_raise_hand = 30
stage_topic = 31
guild_application_premium_subscription = 32
guild_incident_alert_mode_enabled = 36
guild_incident_alert_mode_disabled = 37
guild_incident_report_raid = 38
guild_incident_report_false_alarm = 39
purchase_notification = 44
poll_result = 46


class VoiceRegion(Enum):
Expand Down Expand Up @@ -1055,6 +1063,13 @@ class PollLayoutType(Enum):
default = 1


class MessageReferenceType(Enum):
"""The message reference's type"""

default = 0
forward = 1


class SubscriptionStatus(Enum):
"""The status of a subscription."""

Expand Down
6 changes: 6 additions & 0 deletions discord/ext/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,9 @@ async def send_help(self, *args: Any) -> Any:
@discord.utils.copy_doc(Message.reply)
async def reply(self, content: str | None = None, **kwargs: Any) -> Message:
return await self.message.reply(content, **kwargs)

@discord.utils.copy_doc(Message.forward_to)
async def forward_to(
self, channel: discord.abc.Messageable, **kwargs: Any
) -> Message:
return await self.message.forward_to(channel, **kwargs)
8 changes: 8 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,14 @@ def is_voice_message(self):
"""
return 8192

@flag_value
def has_snapshot(self):
""":class:`bool`: Returns ``True`` if this message has a snapshot from message forwarding.

.. versionadded:: 2.7
"""
return 1 << 14


@fill_with_flags()
class PublicUserFlags(BaseFlags):
Expand Down
Loading