Browse Source

Add support for guild_banner and display_banner

pull/9898/head
Rapptz 9 months ago
parent
commit
a13fc8f835
  1. 11
      discord/asset.py
  2. 24
      discord/member.py
  3. 1
      discord/types/member.py

11
discord/asset.py

@ -246,6 +246,17 @@ class Asset(AssetMixin):
animated=animated,
)
@classmethod
def _from_guild_banner(cls, state: _State, guild_id: int, member_id: int, banner: str) -> Self:
animated = banner.startswith('a_')
format = 'gif' if animated else 'png'
return cls(
state,
url=f"{cls.BASE}/guilds/{guild_id}/users/{member_id}/banners/{banner}.{format}?size=1024",
key=banner,
animated=animated,
)
@classmethod
def _from_avatar_decoration(cls, state: _State, avatar_decoration: str) -> Self:
return cls(

24
discord/member.py

@ -322,6 +322,7 @@ class Member(discord.abc.Messageable, _UserTag):
'_user',
'_state',
'_avatar',
'_banner',
'_flags',
'_avatar_decoration_data',
)
@ -358,6 +359,7 @@ class Member(discord.abc.Messageable, _UserTag):
self.nick: Optional[str] = data.get('nick', None)
self.pending: bool = data.get('pending', False)
self._avatar: Optional[str] = data.get('avatar')
self._banner: Optional[str] = data.get('banner')
self._permissions: Optional[int]
self._flags: int = data['flags']
self._avatar_decoration_data: Optional[AvatarDecorationData] = data.get('avatar_decoration_data')
@ -649,6 +651,28 @@ class Member(discord.abc.Messageable, _UserTag):
return None
return Asset._from_guild_avatar(self._state, self.guild.id, self.id, self._avatar)
@property
def display_banner(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Returns the member's displayed banner, if any.
This is the member's guild banner if available, otherwise it's their
global banner. If the member has no banner set then ``None`` is returned.
.. versionadded:: 2.5
"""
return self.guild_banner or self._user.banner
@property
def guild_banner(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Returns an :class:`Asset` for the guild banner
the member has. If unavailable, ``None`` is returned.
.. versionadded:: 2.5
"""
if self._banner is None:
return None
return Asset._from_guild_banner(self._state, self.guild.id, self.id, self._banner)
@property
def activity(self) -> Optional[ActivityTypes]:
"""Optional[Union[:class:`BaseActivity`, :class:`Spotify`]]: Returns the primary

1
discord/types/member.py

@ -48,6 +48,7 @@ class Member(PartialMember, total=False):
pending: bool
permissions: str
communication_disabled_until: str
banner: NotRequired[Optional[str]]
avatar_decoration_data: NotRequired[AvatarDecorationData]

Loading…
Cancel
Save