diff --git a/changelog/1025.feature.rst b/changelog/1025.feature.rst index 7a063ba158..714dcdf4c8 100644 --- a/changelog/1025.feature.rst +++ b/changelog/1025.feature.rst @@ -4,4 +4,4 @@ Add support for new username system - see the official `help article `__ for details. Existing functionality is kept backwards-compatible while the migration is still ongoing. +- Add :attr:`User.global_name`, and update attributes/methods to account for it: + - :attr:`User.display_name` and :attr:`Member.display_name` + - :meth:`Guild.get_member_named` + - |commands| :class:`~ext.commands.UserConverter` and :class:`~ext.commands.MemberConverter`, now largely matching the behavior of :meth:`Guild.get_member_named` +- Update ``str(user)`` and ``str(member)`` to not include ``#0`` discriminator of migrated users. +- Adjust :attr:`User.default_avatar` to account for new default avatar handling, also adding :attr:`DefaultAvatar.fuchsia`. diff --git a/disnake/abc.py b/disnake/abc.py index d7a2991297..78abdbb623 100644 --- a/disnake/abc.py +++ b/disnake/abc.py @@ -143,8 +143,6 @@ class User(Snowflake, Protocol): The user's global display name, if set. This takes precedence over :attr:`.name` when shown. - For bots, this is the application name. - .. versionadded:: 2.9 avatar: :class:`~disnake.Asset` diff --git a/disnake/enums.py b/disnake/enums.py index 7937c1d1e9..54b25d2f72 100644 --- a/disnake/enums.py +++ b/disnake/enums.py @@ -322,6 +322,7 @@ class DefaultAvatar(Enum): green = 2 orange = 3 red = 4 + fuchsia = 5 def __str__(self) -> str: return self.name diff --git a/disnake/guild.py b/disnake/guild.py index 817d40b442..d68ff87e0e 100644 --- a/disnake/guild.py +++ b/disnake/guild.py @@ -1141,8 +1141,7 @@ def get_member_named(self, name: str, /) -> Optional[Member]: 2. Lookup by global name. 3. Lookup by username. - While the migration away from discriminators is still ongoing, - the name can have an optional discriminator argument, e.g. "Jake#0001", + The name can have an optional discriminator argument, e.g. "Jake#0001", in which case it will be treated as a username + discriminator combo (note: this only works with usernames, not nicknames). diff --git a/disnake/member.py b/disnake/member.py index 96db64f907..daf8fa7cbf 100644 --- a/disnake/member.py +++ b/disnake/member.py @@ -491,7 +491,7 @@ def tag(self) -> str: @property def discriminator(self) -> str: - """:class:`str`:The user's discriminator. + """:class:`str`: The user's discriminator. .. note:: This is being phased out by Discord; the username system is moving away from ``username#discriminator`` diff --git a/disnake/user.py b/disnake/user.py index 8f9333b9cd..b2b05acb54 100644 --- a/disnake/user.py +++ b/disnake/user.py @@ -8,7 +8,7 @@ from .asset import Asset from .colour import Colour -from .enums import DefaultAvatar, Locale, try_enum +from .enums import Locale, try_enum from .flags import PublicUserFlags from .utils import MISSING, _assetbytes_to_base64_data, snowflake_time @@ -157,11 +157,11 @@ def default_avatar(self) -> Asset: Added handling for users migrated to the new username system without discriminators. """ if self.discriminator == "0": - num = self.id >> 22 + index = (self.id >> 22) % 6 else: # legacy behavior - num = int(self.discriminator) - return Asset._from_default_avatar(self._state, num % len(DefaultAvatar)) + index = int(self.discriminator) % 5 + return Asset._from_default_avatar(self._state, index) @property def display_avatar(self) -> Asset: @@ -308,18 +308,10 @@ class ClientUser(BaseUser): discriminator: :class:`str` The user's discriminator. - .. note:: - This is being phased out by Discord; the username system is moving away from ``username#discriminator`` - to users having a globally unique username. - The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. - See the `help article `__ for details. - global_name: Optional[:class:`str`] The user's global display name, if set. This takes precedence over :attr:`.name` when shown. - For bots, this is the application name. - .. versionadded:: 2.9 bot: :class:`bool` @@ -464,8 +456,6 @@ class User(BaseUser, disnake.abc.Messageable): The user's global display name, if set. This takes precedence over :attr:`.name` when shown. - For bots, this is the application name. - .. versionadded:: 2.9 bot: :class:`bool` diff --git a/docs/api/users.rst b/docs/api/users.rst index 274b84aac9..36bfdc1faa 100644 --- a/docs/api/users.rst +++ b/docs/api/users.rst @@ -127,7 +127,7 @@ DefaultAvatar .. class:: DefaultAvatar - Represents the default avatar of a Discord :class:`User` + Represents the default avatar of a Discord :class:`User`. .. attribute:: blurple @@ -152,6 +152,12 @@ DefaultAvatar Represents the default avatar with the color red. See also :attr:`Colour.red` + .. attribute:: fuchsia + + Represents the default avatar with the color fuchsia. + See also :attr:`Colour.fuchsia` + + .. versionadded:: 2.9 Events ------