Browse Source

on_member_update now takes in the older member state as a parameter.

pull/53/head
Rapptz 9 years ago
parent
commit
343e3376ea
  1. 10
      discord/client.py
  2. 12
      docs/api.rst

10
discord/client.py

@ -206,16 +206,15 @@ class ConnectionState(object):
member_id = user['id']
member = utils.find(lambda m: m.id == member_id, server.members)
if member is not None:
old_status = copy.copy(member.status)
old_game_id = copy.copy(member.game_id)
old_member = copy.copy(member)
member.status = data.get('status')
member.game_id = data.get('game_id')
member.name = user.get('username', member.name)
member.avatar = user.get('avatar', member.avatar)
# call the event now
self.dispatch('status', member, old_game_id, old_status)
self.dispatch('member_update', member)
self.dispatch('status', member, old_member.game_id, old_member.status)
self.dispatch('member_update', old_member, member)
def handle_user_update(self, data):
self.user = User(**data)
@ -276,6 +275,7 @@ class ConnectionState(object):
member = utils.find(lambda m: m.id == user_id, server.members)
if member is not None:
user = data['user']
old_member = copy.copy(member)
member.name = user['username']
member.discriminator = user['discriminator']
member.avatar = user['avatar']
@ -285,7 +285,7 @@ class ConnectionState(object):
if role.id in data['roles']:
member.roles.append(role)
self.dispatch('member_update', member)
self.dispatch('member_update', old_member, member)
def handle_guild_create(self, data):
unavailable = data.get('unavailable')

12
docs/api.rst

@ -184,11 +184,19 @@ to handle it, which defaults to print a traceback and ignore the exception.
:param member: The :class:`Member` that joined or left.
.. function:: on_member_update(member)
.. function:: on_member_update(before, after)
Called when a :class:`Member` updates their profile.
:param member: The :class:`Member` that updated their profile with the updated info.
This is called when one or more of the following things change:
- status
- game playing
- avatar
- nickname
:param before: The :class:`Member` that updated their profile with the old info.
:param after: The :class:`Member` that updated their profile with the updated info.
.. function:: on_server_join(server)

Loading…
Cancel
Save