From c261f7c4a35cfc9258036793bfa8b7d4315f2547 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 4 Sep 2020 08:32:02 -0400 Subject: [PATCH] Handle user updates within GUILD_MEMBER_UPDATE --- discord/member.py | 21 ++++++++++++--------- discord/state.py | 6 +++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/discord/member.py b/discord/member.py index dbcbc492d..00f72fb2f 100644 --- a/discord/member.py +++ b/discord/member.py @@ -272,17 +272,20 @@ class Member(discord.abc.Messageable, _BaseUser): self._client_status[None] = data['status'] if len(user) > 1: - u = self._user - original = (u.name, u.avatar, u.discriminator) - # These keys seem to always be available - modified = (user['username'], user['avatar'], user['discriminator']) - if original != modified: - to_return = User._copy(self._user) - u.name, u.avatar, u.discriminator = modified - # Signal to dispatch on_user_update - return to_return, u + return self._update_inner_user(user) return False + def _update_inner_user(self, user): + u = self._user + original = (u.name, u.avatar, u.discriminator) + # These keys seem to always be available + modified = (user['username'], user['avatar'], user['discriminator']) + if original != modified: + to_return = User._copy(self._user) + u.name, u.avatar, u.discriminator = modified + # Signal to dispatch on_user_update + return to_return, u + @property def status(self): """:class:`Status`: The member's overall status. If the value is unknown, then it will be a :class:`str` instead.""" diff --git a/discord/state.py b/discord/state.py index bcbc70b04..a2a2dee64 100644 --- a/discord/state.py +++ b/discord/state.py @@ -698,8 +698,12 @@ class ConnectionState: member = guild.get_member(user_id) if member is not None: - old_member = copy.copy(member) + old_member = Member._copy(member) member._update(data) + user_update = member._update_inner_user(user) + if user_update: + self.dispatch('user_update', user_update[0], user_update[1]) + self.dispatch('member_update', old_member, member) else: log.debug('GUILD_MEMBER_UPDATE referencing an unknown member ID: %s. Discarding.', user_id)