Skip to content

Commit 9cb650e

Browse files
committed
feat: pre-emptive support for user.global_name
i really dont get why this is a thing, but meh, supported
1 parent cf6d76f commit 9cb650e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

interactions/models/discord/user.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class BaseUser(DiscordObject, _SendDMMixin):
4848
"""Base class for User, essentially partial user discord model."""
4949

5050
username: str = attrs.field(repr=True, metadata=docs("The user's username, not unique across the platform"))
51+
global_name: str | None = attrs.field(repr=True, metadata=docs("The user's chosen display name, platform-wide"))
5152
discriminator: int = attrs.field(repr=True, metadata=docs("The user's 4-digit discord-tag"))
5253
avatar: "Asset" = attrs.field(repr=False, metadata=docs("The user's default avatar"))
5354

@@ -76,7 +77,7 @@ def mention(self) -> str:
7677
@property
7778
def display_name(self) -> str:
7879
"""The users display name, will return nickname if one is set, otherwise will return username."""
79-
return self.username # for duck-typing compatibility with Member
80+
return self.global_name or self.username
8081

8182
@property
8283
def display_avatar(self) -> "Asset":
@@ -378,7 +379,7 @@ def top_role(self) -> "Role":
378379
@property
379380
def display_name(self) -> str:
380381
"""The users display name, will return nickname if one is set, otherwise will return username."""
381-
return self.nickname or self.username
382+
return self.nickname or self.user.global_name or self.user.username
382383

383384
@property
384385
def display_avatar(self) -> "Asset":

interactions/models/discord/user.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class _SendDMMixin(SendMixin):
3838
@attrs.define(eq=False, order=False, hash=False, kw_only=True) # properly typehints added attributes by attrs
3939
class FakeBaseUserMixin(DiscordObject, _SendDMMixin):
4040
username: str
41+
global_name: str | None
4142
discriminator: int
4243
avatar: Asset
4344
def __str__(self) -> str: ...

0 commit comments

Comments
 (0)