3535 PremiumType ,
3636 RelationshipAction ,
3737 RelationshipType ,
38+ NameEffect ,
39+ NameFont ,
3840 try_enum ,
3941)
4042from .errors import NotFound
7375 UserAvatar as UserAvatarPayload ,
7476 AvatarDecorationData ,
7577 PrimaryGuild as PrimaryGuildPayload ,
78+ DisplayNameStyle as DisplayNameStylePayload
7679 )
7780 from .types .snowflake import Snowflake
7881
8184 'User' ,
8285 'ClientUser' ,
8386 'RecentAvatar' ,
87+ 'DisplayNameStyle' ,
8488)
8589
8690
8791class _UserTag :
8892 __slots__ = ()
8993 id : int
9094
95+ class DisplayNameStyle :
96+ """Represents a user's display name style.
97+
98+ .. versionadded:: 2.1
99+
100+ Attributes
101+ -----------
102+ font: :class:`NameFont`
103+ The font used for the display name.
104+ effect: :class:`NameEffect`
105+ The visual effect applied to the display name.
106+ colors: List[:class:`Colour`]
107+ The list of colours applied to the display name.
108+ """
109+ def __init__ (self , * , data : DisplayNameStylePayload ) -> None :
110+ self .font : NameFont = try_enum (NameFont , data ['font_id' ])
111+ self .effect : NameEffect = try_enum (NameEffect , data ['effect_id' ])
112+ self .colors : List [discord .Colour ] = [discord .Colour (color ) for color in data .get ('colors' , [])]
113+
114+ def __repr__ (self ) -> str :
115+ return f'<DisplayNameStyle font={ self .font } effect={ self .effect } colors={ self .colors } >'
91116
92117class BaseUser (_UserTag ):
93118 __slots__ = (
@@ -105,6 +130,7 @@ class BaseUser(_UserTag):
105130 'premium_type' ,
106131 '_state' ,
107132 '_primary_guild' ,
133+ '_display_name_style' ,
108134 )
109135
110136 if TYPE_CHECKING :
@@ -121,6 +147,7 @@ class BaseUser(_UserTag):
121147 _accent_colour : Optional [int ]
122148 _public_flags : int
123149 _primary_guild : Optional [PrimaryGuildPayload ]
150+ _display_name_style : Optional [DisplayNameStylePayload ]
124151
125152 def __init__ (self , * , state : ConnectionState , data : Union [UserPayload , PartialUserPayload ]) -> None :
126153 self ._state = state
@@ -159,6 +186,7 @@ def _update(self, data: Union[UserPayload, PartialUserPayload]) -> None:
159186 self .bot = data .get ('bot' , False )
160187 self .system = data .get ('system' , False )
161188 self ._primary_guild = data .get ('primary_guild' , None )
189+ self ._display_name_style = data .get ('display_name_styles' , None ) or None
162190
163191 @classmethod
164192 def _copy (cls , user : Self ) -> Self :
@@ -177,6 +205,7 @@ def _copy(cls, user: Self) -> Self:
177205 self .system = user .system
178206 self ._state = user ._state
179207 self ._primary_guild = user ._primary_guild
208+ self ._display_name_style = user ._display_name_style
180209
181210 return self
182211
@@ -194,6 +223,7 @@ def _to_minimal_user_json(self) -> APIUserPayload:
194223 'banner' : self ._banner ,
195224 'accent_color' : self ._accent_colour ,
196225 'primary_guild' : self ._primary_guild ,
226+ 'display_name_styles' : self ._display_name_style ,
197227 }
198228 return user
199229
@@ -383,6 +413,16 @@ def primary_guild(self) -> PrimaryGuild:
383413 return PrimaryGuild (state = self ._state , data = self ._primary_guild )
384414 return PrimaryGuild ._default (self ._state )
385415
416+ @property
417+ def display_name_style (self ) -> Optional [DisplayNameStyle ]:
418+ """:class:`DisplayNameStyle`: Returns the user's display name style.
419+
420+ .. versionadded:: 2.1
421+ """
422+ if self ._display_name_style is None :
423+ return None
424+ return DisplayNameStyle (data = self ._display_name_style )
425+
386426 def mentioned_in (self , message : Message ) -> bool :
387427 """Checks if the user is mentioned in the specified message.
388428
@@ -1021,6 +1061,7 @@ def _update_self(self, user: Union[PartialUserPayload, Tuple[()]]) -> Optional[T
10211061 self ._avatar_decoration_data ,
10221062 self .global_name ,
10231063 self ._primary_guild ,
1064+ self ._display_name_style ,
10241065 )
10251066 modified = (
10261067 user ['username' ],
@@ -1030,6 +1071,7 @@ def _update_self(self, user: Union[PartialUserPayload, Tuple[()]]) -> Optional[T
10301071 user .get ('avatar_decoration_data' ),
10311072 user .get ('global_name' ),
10321073 user .get ('primary_guild' ),
1074+ user .get ('display_name_styles' ),
10331075 )
10341076 if original != modified :
10351077 to_return = User ._copy (self )
@@ -1041,6 +1083,7 @@ def _update_self(self, user: Union[PartialUserPayload, Tuple[()]]) -> Optional[T
10411083 self ._avatar_decoration_data ,
10421084 self .global_name ,
10431085 self ._primary_guild ,
1086+ self ._display_name_style ,
10441087 ) = modified
10451088 # Signal to dispatch user_update
10461089 return to_return , self
0 commit comments