Skip to content

Commit

Permalink
feat: Member.display_banner (#2556)
Browse files Browse the repository at this point in the history
Signed-off-by: Matty Widdop <[email protected]>
Signed-off-by: Lala Sabathil <[email protected]>
Signed-off-by: Dorukyum <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lala Sabathil <[email protected]>
Co-authored-by: Dorukyum <[email protected]>
Co-authored-by: Lala Sabathil <[email protected]>
Co-authored-by: YoggieS <[email protected]>
Co-authored-by: plun1331 <[email protected]>
  • Loading branch information
7 people authored Aug 29, 2024
1 parent 2136691 commit 7f2beb7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ These changes are available on the `master` branch, but have not yet been releas

- Added `Guild.fetch_role` method.
([#2528](https://github.com/Pycord-Development/pycord/pull/2528))
- Added `Member.guild_banner` and `Member.display_banner` properties.
([#2556](https://github.com/Pycord-Development/pycord/pull/2556))

### Fixed

Expand Down
13 changes: 13 additions & 0 deletions discord/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,19 @@ def _from_guild_avatar(
animated=animated,
)

@classmethod
def _from_guild_banner(
cls, state, guild_id: int, member_id: int, banner: str
) -> Asset:
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=512",
key=banner,
animated=animated,
)

@classmethod
def _from_icon(cls, state, object_id: int, icon_hash: str, path: str) -> Asset:
return cls(
Expand Down
29 changes: 29 additions & 0 deletions discord/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class Member(discord.abc.Messageable, _UserTag):
"_user",
"_state",
"_avatar",
"_banner",
"communication_disabled_until",
"flags",
)
Expand Down Expand Up @@ -328,6 +329,7 @@ def __init__(
self.nick: str | None = data.get("nick", None)
self.pending: bool = data.get("pending", False)
self._avatar: str | None = data.get("avatar")
self._banner: str | None = data.get("banner")
self.communication_disabled_until: datetime.datetime | None = utils.parse_time(
data.get("communication_disabled_until")
)
Expand Down Expand Up @@ -406,6 +408,7 @@ def _copy(cls: type[M], member: M) -> M:
self.activities = member.activities
self._state = member._state
self._avatar = member._avatar
self._banner = member._banner
self.communication_disabled_until = member.communication_disabled_until
self.flags = member.flags

Expand Down Expand Up @@ -434,6 +437,7 @@ def _update(self, data: MemberPayload) -> None:
self.premium_since = utils.parse_time(data.get("premium_since"))
self._roles = utils.SnowflakeList(map(int, data["roles"]))
self._avatar = data.get("avatar")
self._banner = data.get("banner")
self.communication_disabled_until = utils.parse_time(
data.get("communication_disabled_until")
)
Expand Down Expand Up @@ -603,6 +607,31 @@ def guild_avatar(self) -> Asset | None:
self._state, self.guild.id, self.id, self._avatar
)

@property
def display_banner(self) -> Asset | None:
"""Returns the member's display banner.
For regular members this is just their banner, but
if they have a guild specific banner then that
is returned instead.
.. versionadded:: 2.7
"""
return self.guild_banner or self._user.banner

@property
def guild_banner(self) -> Asset | None:
"""Returns an :class:`Asset` for the guild banner
the member has. If unavailable, ``None`` is returned.
.. versionadded:: 2.7
"""
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) -> ActivityTypes | None:
"""Returns the primary
Expand Down
1 change: 1 addition & 0 deletions discord/types/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PartialMember(TypedDict):

class Member(PartialMember, total=False):
avatar: str
banner: str
user: User
nick: str
premium_since: str
Expand Down

0 comments on commit 7f2beb7

Please sign in to comment.