Skip to content

Commit 7ceb11b

Browse files
authored
feat: ✨ Add Member.display_avatar_decoration and Member.guild_avatar_decoration (#3109)
* Fix User.nameplate being entirely broken * Fix nameplate updating * Add nameplate bug changelog * Turn nameplate into a property for cleaner handling * Remove unnecessary import * Turn primary_guild into a property for easier handling * Make event fire on avatar decoration change * Update changelog * First semi-working version * Add new class to docs * Fix PR number * Fix typo.. * Add ability to compare collectibles and nameplates * Minor fix * Missing word * Simplify nameplate return code * Move __all__ up * Apply code change requests * Make sure attribute shows in IDEs * Apply code change requests * Update changelog * Implement `Member.display_avatar_decoration` * Apply code change requests * Apply code change requests * Correct typehint * Add avatar decoration type * Add avatar decoration field to member type --------- Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com>
1 parent 6efa686 commit 7ceb11b

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ These changes are available on the `master` branch, but have not yet been releas
2020
([#3107](https://github.com/Pycord-Development/pycord/pull/3107))
2121
- Added the ability to compare instances of `Nameplate`.
2222
([#3107](https://github.com/Pycord-Development/pycord/pull/3107))
23+
- Added `Member.display_avatar_decoration` and `Member.guild_avatar_decoration`.
24+
([#3109](https://github.com/Pycord-Development/pycord/pull/3109))
2325

2426
### Changed
2527

discord/member.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from .permissions import Permissions
4747
from .primary_guild import PrimaryGuild
4848
from .role import RoleColours
49+
from .types.collectibles import AvatarDecoration
4950
from .user import BaseUser, User, _UserTag
5051
from .utils import MISSING
5152

@@ -296,6 +297,7 @@ class Member(discord.abc.Messageable, _UserTag):
296297
"_banner",
297298
"communication_disabled_until",
298299
"flags",
300+
"_avatar_decoration",
299301
)
300302

301303
if TYPE_CHECKING:
@@ -317,6 +319,7 @@ class Member(discord.abc.Messageable, _UserTag):
317319
communication_disabled_until: datetime.datetime | None
318320
primary_guild: PrimaryGuild | None
319321
collectibles: Collectibles | None
322+
avatar_decoration: Asset | None
320323

321324
def __init__(
322325
self, *, data: MemberWithUserPayload, guild: Guild, state: ConnectionState
@@ -341,6 +344,9 @@ def __init__(
341344
data.get("communication_disabled_until")
342345
)
343346
self.flags: MemberFlags = MemberFlags._from_value(data.get("flags", 0))
347+
self._avatar_decoration: AvatarDecoration | None = data.get(
348+
"avatar_decoration_data"
349+
)
344350

345351
def __str__(self) -> str:
346352
return str(self._user)
@@ -418,6 +424,7 @@ def _copy(cls: type[M], member: M) -> M:
418424
self._banner = member._banner
419425
self.communication_disabled_until = member.communication_disabled_until
420426
self.flags = member.flags
427+
self._avatar_decoration = member._avatar_decoration
421428

422429
# Reference will not be copied unless necessary by PRESENCE_UPDATE
423430
# See below
@@ -449,6 +456,7 @@ def _update(self, data: MemberPayload) -> None:
449456
data.get("communication_disabled_until")
450457
)
451458
self.flags = MemberFlags._from_value(data.get("flags", 0))
459+
self._avatar_decoration = data.get("avatar_decoration_data")
452460

453461
def _presence_update(
454462
self, data: PartialPresenceUpdate, user: UserPayload
@@ -663,6 +671,31 @@ def guild_avatar(self) -> Asset | None:
663671
self._state, self.guild.id, self.id, self._avatar
664672
)
665673

674+
@property
675+
def display_avatar_decoration(self) -> Asset | None:
676+
"""Returns the member's displayed avatar decoration.
677+
678+
For regular members this is just their avatar decoration, but
679+
if they have a guild specific avatar decoration then that
680+
is returned instead.
681+
682+
.. versionadded:: 2.8
683+
"""
684+
return self.guild_avatar_decoration or self._user.avatar_decoration
685+
686+
@property
687+
def guild_avatar_decoration(self) -> Asset | None:
688+
"""Returns an :class:`Asset` for the guild specific avatar decoration
689+
the member has. If unavailable, ``None`` is returned.
690+
691+
.. versionadded:: 2.8
692+
"""
693+
if self._avatar_decoration is None:
694+
return None
695+
return Asset._from_avatar_decoration(
696+
self._state, self.id, self._avatar_decoration.get("asset")
697+
)
698+
666699
@property
667700
def display_banner(self) -> Asset | None:
668701
"""Returns the member's display banner.

discord/types/collectibles.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ class Nameplate(TypedDict):
3838
asset: str
3939
label: str
4040
palette: str
41+
42+
43+
class AvatarDecoration(TypedDict):
44+
sku_id: Snowflake
45+
asset: str

discord/types/member.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from typing import TypedDict
2727

28-
from .collectibles import Collectibles
28+
from .collectibles import AvatarDecoration, Collectibles
2929
from .snowflake import SnowflakeList
3030
from .user import User
3131

@@ -52,6 +52,7 @@ class Member(PartialMember, total=False):
5252
communication_disabled_until: str
5353
flags: int
5454
collectibles: Collectibles
55+
avatar_decoration_data: AvatarDecoration
5556

5657

5758
class _OptionalMemberWithUser(PartialMember, total=False):
@@ -60,6 +61,7 @@ class _OptionalMemberWithUser(PartialMember, total=False):
6061
premium_since: str
6162
pending: bool
6263
permissions: str
64+
avatar_decoration_data: AvatarDecoration
6365

6466

6567
class MemberWithUser(_OptionalMemberWithUser):

0 commit comments

Comments
 (0)