Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(member): implement member banners #1204

Merged
merged 9 commits into from
Nov 16, 2024
1 change: 1 addition & 0 deletions changelog/1203.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement new :attr:`.Member.guild_banner` property.
13 changes: 13 additions & 0 deletions disnake/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ def _from_guild_avatar(
animated=animated,
)

@classmethod
def _from_guild_banner(
cls, state: AnyState, 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_icon(cls, state: AnyState, object_id: int, icon_hash: str, path: str) -> Self:
return cls(
Expand Down
13 changes: 13 additions & 0 deletions disnake/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class Member(disnake.abc.Messageable, _UserTag):
"_user",
"_state",
"_avatar",
"_banner",
"_communication_disabled_until",
"_flags",
"_avatar_decoration_data",
Expand Down Expand Up @@ -340,6 +341,7 @@ def __init__(
self.nick: Optional[str] = data.get("nick")
self.pending: bool = data.get("pending", False)
self._avatar: Optional[str] = data.get("avatar")
self._banner: Optional[str] = data.get("banner")
onerandomusername marked this conversation as resolved.
Show resolved Hide resolved
timeout_datetime = utils.parse_time(data.get("communication_disabled_until"))
self._communication_disabled_until: Optional[datetime.datetime] = timeout_datetime
self._flags: int = data.get("flags", 0)
Expand Down Expand Up @@ -619,6 +621,17 @@ def guild_avatar(self) -> Optional[Asset]:
return None
return Asset._from_guild_avatar(self._state, self.guild.id, self.id, self._avatar)

@property
def guild_banner(self) -> Optional[Asset]:
Snipy7374 marked this conversation as resolved.
Show resolved Hide resolved
"""Optional[:class:`Asset`]: Returns an :class:`Asset` for the guild banner
the member has. If unavailable, ``None`` is returned.

.. versionadded:: 2.10
"""
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
Expand Down
Loading