Skip to content
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

feat: add Message._raw_data #2670

Merged
merged 11 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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 @@ -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.data` and `Message.to_dict()`.
([#2670](https://github.com/Pycord-Development/pycord/pull/2670))

### Fixed

Expand Down
17 changes: 17 additions & 0 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +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",
"_edited_timestamp",
"_cs_channel_mentions",
"_cs_raw_mentions",
Expand Down Expand Up @@ -842,6 +847,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] = [
Expand Down Expand Up @@ -1991,6 +1997,17 @@ def to_message_reference_dict(self) -> MessageReferencePayload:

return data

def to_dict(self) -> MessagePayload:
tibue99 marked this conversation as resolved.
Show resolved Hide resolved
tibue99 marked this conversation as resolved.
Show resolved Hide resolved
tibue99 marked this conversation as resolved.
Show resolved Hide resolved
"""Converts this message object into a dict.
tibue99 marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
Loading