aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discord/raw_models.py7
-rw-r--r--discord/state.py5
-rw-r--r--docs/api.rst3
3 files changed, 12 insertions, 3 deletions
diff --git a/discord/raw_models.py b/discord/raw_models.py
index 211216af..72de4450 100644
--- a/discord/raw_models.py
+++ b/discord/raw_models.py
@@ -86,14 +86,17 @@ class RawMessageUpdateEvent:
The message ID that got updated.
data: :class:`dict`
The raw data given by the
- `gateway <https://discordapp.com/developers/docs/topics/gateway#message-update>`_
+ `gateway <https://discordapp.com/developers/docs/topics/gateway#message-update>`
+ cached_message: Optional[:class:`Message`]
+ The cached message, if found in the internal message cache.
"""
- __slots__ = ('message_id', 'data')
+ __slots__ = ('message_id', 'data', 'cached_message')
def __init__(self, data):
self.message_id = int(data['id'])
self.data = data
+ self.cached_message = None
class RawReactionActionEvent:
"""Represents the payload for a :func:`on_raw_reaction_add` or
diff --git a/discord/state.py b/discord/state.py
index a603c55d..f04d6ee7 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -386,10 +386,11 @@ class ConnectionState:
def parse_message_update(self, data):
raw = RawMessageUpdateEvent(data)
- self.dispatch('raw_message_edit', raw)
message = self._get_message(raw.message_id)
if message is not None:
older_message = copy.copy(message)
+ raw.cached_message = older_message
+ self.dispatch('raw_message_edit', raw)
if 'call' in data:
# call state message edit
message._handle_call(data['call'])
@@ -400,6 +401,8 @@ class ConnectionState:
message._update(channel=message.channel, data=data)
self.dispatch('message_edit', older_message, message)
+ else:
+ self.dispatch('raw_message_edit', raw)
def parse_message_reaction_add(self, data):
emoji_data = data['emoji']
diff --git a/docs/api.rst b/docs/api.rst
index 09d4d0c6..78a96f45 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -296,6 +296,9 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a message is edited. Unlike :func:`on_message_edit`, this is called
regardless of the state of the internal message cache.
+ If the message is found in the message cache,
+ it can be accessed via :attr:`RawMessageUpdateEvent.cached_message`
+
Due to the inherently raw nature of this event, the data parameter coincides with
the raw data given by the `gateway <https://discordapp.com/developers/docs/topics/gateway#message-update>`_