Skip to content

Commit 5a06cc7

Browse files
ToothyDevpre-commit-ci[bot]JustaSqu1d
authored
fix: 🐛 Fix docs rendering for ForwardedMessage and MessageSnapshot and add missing attributes (#3051)
* 📝 Add missing rendering for MessageSnapshot in docs * 📝 Add missing rendering for ForwardedMessage in docs * 🐛 Add missing mentions property for ForwardedMessage * style(pre-commit): auto fixes from pre-commit.com hooks * Add to changelog * style(pre-commit): auto fixes from pre-commit.com hooks * Correct data conversion * Correct docstring data type * 📝 Add note in docs to inform about empty list possibility * 📝 Update role_mentions docs to warn about its usage * Implement type attribute * Update changelog accordingly * Copy role mentions logic from `Message` This knowingly doesn't work yet due to a Discord limitation / unresolved discussion on the API. A warning in the docs is in place * Add missing type information * Update changelog * Update CHANGELOG.md , Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> --------- Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
1 parent 54983dc commit 5a06cc7

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ These changes are available on the `master` branch, but have not yet been releas
3030
- Fixed `Interaction.channel` not being resolved with user-installed commands ran in
3131
guilds which the bot is not a member of.
3232
([#3047](https://github.com/Pycord-Development/pycord/pull/3047))
33+
- Fixed the `ForwardedMessage.mentions`, `ForwardedMessage.role_mentions`, and
34+
`ForwardedMessage.type` attributes not being populated.
35+
([#3051](https://github.com/Pycord-Development/pycord/pull/3051))
3336

3437
- Fixed incorrect page group assignment in `Paginator`.
3538
([#3065](https://github.com/Pycord-Development/pycord/pull/3065))

discord/message.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"MessageCall",
108108
"DeletedReferencedMessage",
109109
"ForwardedMessage",
110+
"MessageSnapshot",
110111
)
111112

112113

@@ -747,10 +748,17 @@ class ForwardedMessage:
747748
A list of attachments given to the original message.
748749
flags: :class:`MessageFlags`
749750
Extra features of the original message.
750-
mentions: List[Union[:class:`abc.User`, :class:`Object`]]
751-
A list of :class:`Member` that were originally mentioned.
752-
role_mentions: List[Union[:class:`Role`, :class:`Object`]]
751+
mentions: List[:class:`User`]
752+
A list of :class:`User` that were originally mentioned.
753+
754+
.. note::
755+
This list will be empty if the message was forwarded to a different place, e.g., from a DM to a guild, or
756+
from one guild to another.
757+
role_mentions: List[:class:`Role`]
753758
A list of :class:`Role` that were originally mentioned.
759+
760+
.. warning::
761+
This is only available using :meth:`abc.Messageable.fetch_message`.
754762
stickers: List[:class:`StickerItem`]
755763
A list of sticker items given to the original message.
756764
components: List[:class:`Component`]
@@ -792,6 +800,17 @@ def __init__(
792800
self.components: list[Component] = [
793801
_component_factory(d) for d in data.get("components", [])
794802
]
803+
self.mentions: list[User] = [
804+
state.create_user(data=user) for user in data["mentions"]
805+
]
806+
self.role_mentions: list[Role] = []
807+
if isinstance(self.guild, Guild) and data.get("mention_roles"):
808+
for role_id in map(int, data["mention_roles"]):
809+
role = self.guild.get_role(role_id)
810+
if role is not None:
811+
self.role_mentions.append(role)
812+
813+
self.type: MessageType = try_enum(MessageType, data["type"])
795814
self._edited_timestamp: datetime.datetime | None = utils.parse_time(
796815
data["edited_timestamp"]
797816
)
@@ -1023,7 +1042,7 @@ class Message(Hashable):
10231042
The call information associated with this message, if applicable.
10241043
10251044
.. versionadded:: 2.6
1026-
snapshots: Optional[List[:class:`MessageSnapshots`]]
1045+
snapshots: Optional[List[:class:`MessageSnapshot`]]
10271046
The snapshots attached to this message, if applicable.
10281047
10291048
.. versionadded:: 2.7

docs/api/models.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ Messages
8989
.. autoclass:: Message()
9090
:members:
9191

92+
.. attributetable:: MessageSnapshot
93+
94+
.. autoclass:: MessageSnapshot()
95+
:members:
96+
97+
.. attributetable:: ForwardedMessage
98+
99+
.. autoclass:: ForwardedMessage()
100+
:members:
101+
92102
.. attributetable:: DeletedReferencedMessage
93103

94104
.. autoclass:: DeletedReferencedMessage()

0 commit comments

Comments
 (0)