aboutsummaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-08-25 01:42:29 -0400
committerRapptz <[email protected]>2021-08-25 01:43:09 -0400
commit848d752388f9878cc4a17148b87ae435d220640d (patch)
treefebbe5db754e1e5bf92494fc23d9ea7850ee0458 /discord
parentChange on_socket_raw_receive to dispatch right before JSON conversion (diff)
downloaddiscord.py-848d752388f9878cc4a17148b87ae435d220640d.tar.xz
discord.py-848d752388f9878cc4a17148b87ae435d220640d.zip
Change User.avatar to be Optional[Asset] instead of Asset
This change was needed to allow users to more easily check if an uploaded avatar was set using `if user.avatar:` rather than the admittedly clunky `if user.avatar != user.default_avatar. The old behaviour with a fallback is still useful for actual display purposes, so it has been moved over to the new `User.display_avatar` attribute. This also has symmetry with the newly added `Member.display_avatar` attribute.
Diffstat (limited to 'discord')
-rw-r--r--discord/member.py4
-rw-r--r--discord/user.py35
2 files changed, 18 insertions, 21 deletions
diff --git a/discord/member.py b/discord/member.py
index 1ff682c4..058b39b2 100644
--- a/discord/member.py
+++ b/discord/member.py
@@ -275,7 +275,7 @@ class Member(discord.abc.Messageable, _UserTag):
system: bool
created_at: datetime.datetime
default_avatar: Asset
- avatar: Asset
+ avatar: Optional[Asset]
dm_channel: Optional[DMChannel]
create_dm = User.create_dm
mutual_guilds: List[Guild]
@@ -513,7 +513,7 @@ class Member(discord.abc.Messageable, _UserTag):
.. versionadded:: 2.0
"""
- return self.guild_avatar or self.avatar
+ return self.guild_avatar or self._user.avatar or self._user.default_avatar
@property
def guild_avatar(self) -> Optional[Asset]:
diff --git a/discord/user.py b/discord/user.py
index 7064c721..57c032ac 100644
--- a/discord/user.py
+++ b/discord/user.py
@@ -147,16 +147,15 @@ class BaseUser(_UserTag):
return PublicUserFlags._from_value(self._public_flags)
@property
- def avatar(self) -> Asset:
- """:class:`Asset`: Returns an :class:`Asset` for the avatar the user has.
+ def avatar(self) -> Optional[Asset]:
+ """Optional[:class:`Asset`]: Returns an :class:`Asset` for the avatar the user has.
- If the user does not have a traditional avatar, an asset for
- the default avatar is returned instead.
+ If the user does not have a traditional avatar, ``None`` is returned.
+ If you want the avatar that a user has displayed, consider :attr:`display_avatar`.
"""
- if self._avatar is None:
- return Asset._from_default_avatar(self._state, int(self.discriminator) % len(DefaultAvatar))
- else:
+ if self._avatar is not None:
return Asset._from_avatar(self._state, self.id, self._avatar)
+ return None
@property
def default_avatar(self) -> Asset:
@@ -164,6 +163,16 @@ class BaseUser(_UserTag):
return Asset._from_default_avatar(self._state, int(self.discriminator) % len(DefaultAvatar))
@property
+ def display_avatar(self) -> Asset:
+ """:class:`Asset`: Returns the user's display avatar.
+
+ For regular users this is just their default avatar or uploaded avatar.
+
+ .. versionadded:: 2.0
+ """
+ return self.avatar or self.default_avatar
+
+ @property
def banner(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Returns the user's banner asset, if available.
@@ -248,18 +257,6 @@ class BaseUser(_UserTag):
"""
return self.name
- @property
- def display_avatar(self) -> Asset:
- """:class:`Asset`: Returns the user's display avatar.
-
- For regular users this is just their avatar, but
- if they have a guild specific avatar then that
- is returned instead.
-
- .. versionadded:: 2.0
- """
- return self.avatar
-
def mentioned_in(self, message: Message) -> bool:
"""Checks if the user is mentioned in the specified message.