From 228c1221a258b99c31db70469506b9283bb88880 Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Sun, 15 Dec 2024 14:08:24 +0100 Subject: [PATCH 01/10] Add message.to_dict --- discord/message.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/discord/message.py b/discord/message.py index 5ebd2aa0ea..0bab5362f3 100644 --- a/discord/message.py +++ b/discord/message.py @@ -789,6 +789,7 @@ class Message(Hashable): __slots__ = ( "_state", + "_data", "_edited_timestamp", "_cs_channel_mentions", "_cs_raw_mentions", @@ -842,6 +843,7 @@ def __init__( data: MessagePayload, ): self._state: ConnectionState = state + self._data: MessagePayload = data self.id: int = int(data["id"]) self.webhook_id: int | None = utils._get_as_snowflake(data, "webhook_id") self.reactions: list[Reaction] = [ @@ -1991,6 +1993,9 @@ def to_message_reference_dict(self) -> MessageReferencePayload: return data + def to_dict(self) -> MessagePayload: + return self._data + class PartialMessage(Hashable): """Represents a partial message to aid with working messages when only From 640a018fa9af1edce159423e34af27b109e4de1d Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Sun, 15 Dec 2024 14:22:03 +0100 Subject: [PATCH 02/10] Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bda9a0ecc..58348d6053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ These changes are available on the `master` branch, but have not yet been releas `Permissions.use_external_sounds` and `Permissions.view_creator_monetization_analytics`. ([#2620](https://github.com/Pycord-Development/pycord/pull/2620)) +- Added `message.to_dict()` method. + ([#2670](https://github.com/Pycord-Development/pycord/pull/2670)) ### Fixed From a779c6f28067dd9c0d6b75df8b5860e249aa92ee Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:07:50 +0100 Subject: [PATCH 03/10] Add __dict__ --- discord/message.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/discord/message.py b/discord/message.py index 0bab5362f3..b266d33858 100644 --- a/discord/message.py +++ b/discord/message.py @@ -954,6 +954,9 @@ def __repr__(self) -> str: f" author={self.author!r} flags={self.flags!r}>" ) + def __dict__(self) -> MessagePayload: + return self.to_dict() + def _try_patch(self, data, key, transform=None) -> None: try: value = data[key] From af5b9fb481d3366de8839d15071fe818dab85f9f Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:42:35 +0100 Subject: [PATCH 04/10] Revert "Add __dict__" This reverts commit a779c6f28067dd9c0d6b75df8b5860e249aa92ee. --- discord/message.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/discord/message.py b/discord/message.py index b266d33858..0bab5362f3 100644 --- a/discord/message.py +++ b/discord/message.py @@ -954,9 +954,6 @@ def __repr__(self) -> str: f" author={self.author!r} flags={self.flags!r}>" ) - def __dict__(self) -> MessagePayload: - return self.to_dict() - def _try_patch(self, data, key, transform=None) -> None: try: value = data[key] From 132617b9d84389c50b2132b04c1111076fb83094 Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Sun, 15 Dec 2024 23:04:13 +0100 Subject: [PATCH 05/10] Update CHANGELOG.md Co-authored-by: Paillat Signed-off-by: Timo <35654063+tibue99@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58348d6053..1111ca9263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ These changes are available on the `master` branch, but have not yet been releas `Permissions.use_external_sounds` and `Permissions.view_creator_monetization_analytics`. ([#2620](https://github.com/Pycord-Development/pycord/pull/2620)) -- Added `message.to_dict()` method. +- Added `Message.to_dict()` method. ([#2670](https://github.com/Pycord-Development/pycord/pull/2670)) ### Fixed From 92ededf8b97478e25f9dc43c6d13fd6baf81baaa Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Sun, 15 Dec 2024 23:13:25 +0100 Subject: [PATCH 06/10] Make message.data public --- CHANGELOG.md | 2 +- discord/message.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1111ca9263..658789241d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ These changes are available on the `master` branch, but have not yet been releas `Permissions.use_external_sounds` and `Permissions.view_creator_monetization_analytics`. ([#2620](https://github.com/Pycord-Development/pycord/pull/2620)) -- Added `Message.to_dict()` method. +- Added `Message.data` and `Message.to_dict()`. ([#2670](https://github.com/Pycord-Development/pycord/pull/2670)) ### Fixed diff --git a/discord/message.py b/discord/message.py index 0bab5362f3..bfb31f01f7 100644 --- a/discord/message.py +++ b/discord/message.py @@ -785,11 +785,15 @@ class Message(Hashable): The call information associated with this message, if applicable. .. versionadded:: 2.6 + data: :class:`MessagePayload` + The data payload that was received to create this message. + + .. versionadded:: 2.7 """ __slots__ = ( "_state", - "_data", + "data", "_edited_timestamp", "_cs_channel_mentions", "_cs_raw_mentions", @@ -843,7 +847,7 @@ def __init__( data: MessagePayload, ): self._state: ConnectionState = state - self._data: MessagePayload = data + self.data: MessagePayload = data self.id: int = int(data["id"]) self.webhook_id: int | None = utils._get_as_snowflake(data, "webhook_id") self.reactions: list[Reaction] = [ @@ -1994,7 +1998,7 @@ def to_message_reference_dict(self) -> MessageReferencePayload: return data def to_dict(self) -> MessagePayload: - return self._data + return self.data class PartialMessage(Hashable): From 9d66ccc8018c67a122eaea979297fef0635d65e2 Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Sun, 15 Dec 2024 23:17:26 +0100 Subject: [PATCH 07/10] Add docstring --- discord/message.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/discord/message.py b/discord/message.py index bfb31f01f7..6b0801bb30 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1998,6 +1998,14 @@ def to_message_reference_dict(self) -> MessageReferencePayload: return data def to_dict(self) -> MessagePayload: + """Converts this message object into a dict. + + Returns + ------- + :class:`~discord.MessagePayload` + A dictionary of :class:`str` message keys bound to the respective value. + """ + return self.data From 29665e1141a030034731e84da16b6386bfe5cd6e Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:33:42 +0100 Subject: [PATCH 08/10] Remove to_dict --- CHANGELOG.md | 2 +- discord/message.py | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 658789241d..7657ab98fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ These changes are available on the `master` branch, but have not yet been releas `Permissions.use_external_sounds` and `Permissions.view_creator_monetization_analytics`. ([#2620](https://github.com/Pycord-Development/pycord/pull/2620)) -- Added `Message.data` and `Message.to_dict()`. +- Added `Message.data` attribute. ([#2670](https://github.com/Pycord-Development/pycord/pull/2670)) ### Fixed diff --git a/discord/message.py b/discord/message.py index 6b0801bb30..8fea0cee73 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1997,17 +1997,6 @@ def to_message_reference_dict(self) -> MessageReferencePayload: return data - def to_dict(self) -> MessagePayload: - """Converts this message object into a dict. - - Returns - ------- - :class:`~discord.MessagePayload` - A dictionary of :class:`str` message keys bound to the respective value. - """ - - return self.data - class PartialMessage(Hashable): """Represents a partial message to aid with working messages when only From bfa2e71ededd897e8258bf42f773544fa5d5a040 Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:20:26 +0100 Subject: [PATCH 09/10] Change docstring type to dict --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index 8fea0cee73..9fe94f8c56 100644 --- a/discord/message.py +++ b/discord/message.py @@ -785,7 +785,7 @@ class Message(Hashable): The call information associated with this message, if applicable. .. versionadded:: 2.6 - data: :class:`MessagePayload` + data: :class:`dict` The data payload that was received to create this message. .. versionadded:: 2.7 From 285b522a57872b2ebede923b4872354e7dfa9f72 Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 30 Dec 2024 18:01:48 +0100 Subject: [PATCH 10/10] Rename to _raw_data --- CHANGELOG.md | 2 +- discord/message.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7657ab98fc..88666beceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ These changes are available on the `master` branch, but have not yet been releas `Permissions.use_external_sounds` and `Permissions.view_creator_monetization_analytics`. ([#2620](https://github.com/Pycord-Development/pycord/pull/2620)) -- Added `Message.data` attribute. +- Added `Message._raw_data` attribute. ([#2670](https://github.com/Pycord-Development/pycord/pull/2670)) ### Fixed diff --git a/discord/message.py b/discord/message.py index 9fe94f8c56..55a6bfd6b4 100644 --- a/discord/message.py +++ b/discord/message.py @@ -785,15 +785,11 @@ class Message(Hashable): The call information associated with this message, if applicable. .. versionadded:: 2.6 - data: :class:`dict` - The data payload that was received to create this message. - - .. versionadded:: 2.7 """ __slots__ = ( "_state", - "data", + "_raw_data", "_edited_timestamp", "_cs_channel_mentions", "_cs_raw_mentions", @@ -847,7 +843,7 @@ def __init__( data: MessagePayload, ): self._state: ConnectionState = state - self.data: MessagePayload = data + self._raw_data: MessagePayload = data self.id: int = int(data["id"]) self.webhook_id: int | None = utils._get_as_snowflake(data, "webhook_id") self.reactions: list[Reaction] = [