Browse Source

Different method of upgrading user instances

pull/2266/head
Rapptz 6 years ago
parent
commit
5c1b239b47
  1. 6
      discord/member.py
  2. 3
      discord/message.py
  3. 9
      discord/user.py

6
discord/member.py

@ -189,11 +189,7 @@ class Member(discord.abc.Messageable, _BaseUser):
@classmethod
def _from_message(cls, *, message, data):
author = message.author
data['user'] = {
attr: getattr(author, attr)
for attr in author.__slots__
if attr[0] != '_'
}
data['user'] = author._to_minimal_user_json()
return cls(data=data, guild=message.guild, state=message._state)
@classmethod

3
discord/message.py

@ -403,9 +403,12 @@ class Message:
# ourselves to a more "partial" member object.
author = self.author
try:
# Update member reference
if author.joined_at is None:
author.joined_at = utils.parse_time(member.get('joined_at'))
except AttributeError:
# It's a user here
# TODO: consider adding to cache here
self.author = Member._from_message(message=self, data=member)
def _handle_mentions(self, mentions):

9
discord/user.py

@ -112,6 +112,15 @@ class BaseUser(_BaseUser):
return self
def _to_minimal_user_json(self):
return {
'name': self.name,
'id': self.id,
'avatar': self.avatar,
'discriminator': self.discriminator,
'bot': self.bot,
}
@property
def avatar_url(self):
"""Returns an :class:`Asset` for the avatar the user has.

Loading…
Cancel
Save