diff --git a/discord/message.py b/discord/message.py index e28bb8ae9..7c255b91a 100644 --- a/discord/message.py +++ b/discord/message.py @@ -243,11 +243,15 @@ class MessageReference: def flatten_handlers(cls): prefix = len('_handle_') - cls._HANDLERS = { - key[prefix:]: value + handlers = [ + (key[prefix:], value) for key, value in cls.__dict__.items() - if key.startswith('_handle_') - } + if key.startswith('_handle_') and key != '_handle_member' + ] + + # store _handle_member last + handlers.append(('member', cls._handle_member)) + cls._HANDLERS = handlers cls._CACHED_SLOTS = [ attr for attr in cls.__slots__ if attr.startswith('_cs_') ] @@ -452,10 +456,13 @@ class Message(Hashable): return reaction def _update(self, data): - handlers = self._HANDLERS - for key, value in data.items(): + # In an update scheme, 'author' key has to be handled before 'member' + # otherwise they overwrite each other which is undesirable. + # Since there's no good way to do this we have to iterate over every + # handler rather than iterating over the keys which is a little slower + for key, handler in self._HANDLERS: try: - handler = handlers[key] + value = data[key] except KeyError: continue else: diff --git a/discord/state.py b/discord/state.py index 838a8f45f..6650ba87f 100644 --- a/discord/state.py +++ b/discord/state.py @@ -526,6 +526,9 @@ class ConnectionState: raw.cached_message = older_message self.dispatch('raw_message_edit', raw) message._update(data) + # Coerce the `after` parameter to take the new updated Member + # ref: #5999 + older_message.author = message.author self.dispatch('message_edit', older_message, message) else: self.dispatch('raw_message_edit', raw)