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.display_banner #2556

Merged
merged 20 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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