diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 1870620f..b74bbfef 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -330,6 +330,10 @@ class AuditLogEntry(Hashable): Returns the entry's hash. + .. describe:: int(x) + + Returns the entry's ID. + .. versionchanged:: 1.7 Audit log entries are now comparable and hashable. diff --git a/discord/channel.py b/discord/channel.py index be3315cf..dc3967c4 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -115,6 +115,10 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): Returns the channel's name. + .. describe:: int(x) + + Returns the channel's ID. + Attributes ----------- name: :class:`str` @@ -1334,6 +1338,10 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable): Returns the category's name. + .. describe:: int(x) + + Returns the category's ID. + Attributes ----------- name: :class:`str` @@ -1556,6 +1564,10 @@ class StoreChannel(discord.abc.GuildChannel, Hashable): Returns the channel's name. + .. describe:: int(x) + + Returns the channel's ID. + Attributes ----------- name: :class:`str` @@ -1728,6 +1740,10 @@ class DMChannel(discord.abc.Messageable, Hashable): Returns a string representation of the channel + .. describe:: int(x) + + Returns the channel's ID. + Attributes ---------- recipient: Optional[:class:`User`] @@ -1854,6 +1870,10 @@ class GroupChannel(discord.abc.Messageable, Hashable): Returns a string representation of the channel + .. describe:: int(x) + + Returns the channel's ID. + Attributes ---------- recipients: List[:class:`User`] @@ -2000,6 +2020,10 @@ class PartialMessageable(discord.abc.Messageable, Hashable): Returns the partial messageable's hash. + .. describe:: int(x) + + Returns the messageable's ID. + Attributes ----------- id: :class:`int` diff --git a/discord/emoji.py b/discord/emoji.py index 8b51d0fd..39fa0218 100644 --- a/discord/emoji.py +++ b/discord/emoji.py @@ -72,6 +72,10 @@ class Emoji(_EmojiTag, AssetMixin): Returns the emoji rendered for discord. + .. describe:: int(x) + + Returns the emoji ID. + Attributes ----------- name: :class:`str` @@ -137,6 +141,9 @@ class Emoji(_EmojiTag, AssetMixin): return f'' return f'<:{self.name}:{self.id}>' + def __int__(self) -> int: + return self.id + def __repr__(self) -> str: return f'' diff --git a/discord/guild.py b/discord/guild.py index 9ab81276..efb7a118 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -140,6 +140,10 @@ class Guild(Hashable): Returns the guild's name. + .. describe:: int(x) + + Returns the guild's ID. + Attributes ---------- name: :class:`str` diff --git a/discord/invite.py b/discord/invite.py index d02fa680..050d2b83 100644 --- a/discord/invite.py +++ b/discord/invite.py @@ -230,6 +230,7 @@ class Invite(Hashable): Returns the invite URL. + The following table illustrates what methods will obtain the attributes: +------------------------------------+------------------------------------------------------------+ @@ -433,6 +434,9 @@ class Invite(Hashable): def __str__(self) -> str: return self.url + def __int__(self) -> int: + return 0 # To keep the object compatible with the hashable abc. + def __repr__(self) -> str: return ( f' str: return str(self._user) + def __int__(self) -> int: + return self.id + def __repr__(self) -> str: return ( f'' ) + + def __str__(self) -> Optional[str]: + return self.content + def _try_patch(self, data, key, transform=None) -> None: try: value = data[key] @@ -1634,6 +1650,10 @@ class PartialMessage(Hashable): Returns the partial message's hash. + .. describe:: int(x) + + Returns the partial message's ID. + Attributes ----------- channel: Union[:class:`TextChannel`, :class:`Thread`, :class:`DMChannel`] diff --git a/discord/mixins.py b/discord/mixins.py index 32ee222b..fdacf863 100644 --- a/discord/mixins.py +++ b/discord/mixins.py @@ -43,5 +43,8 @@ class EqualityComparable: class Hashable(EqualityComparable): __slots__ = () + def __int__(self) -> int: + return self.id + def __hash__(self) -> int: return self.id >> 22 diff --git a/discord/object.py b/discord/object.py index 3795425f..8061a8be 100644 --- a/discord/object.py +++ b/discord/object.py @@ -69,6 +69,10 @@ class Object(Hashable): Returns the object's hash. + .. describe:: int(x) + + Returns the object's ID. + Attributes ----------- id: :class:`int` diff --git a/discord/role.py b/discord/role.py index 0427ddc3..b690cbe4 100644 --- a/discord/role.py +++ b/discord/role.py @@ -141,6 +141,14 @@ class Role(Hashable): Returns the role's name. + .. describe:: str(x) + + Returns the role's ID. + + .. describe:: int(x) + + Returns the role's ID. + Attributes ---------- id: :class:`int` @@ -195,6 +203,9 @@ class Role(Hashable): def __str__(self) -> str: return self.name + def __int__(self) -> int: + return self.id + def __repr__(self) -> str: return f'' diff --git a/discord/stage_instance.py b/discord/stage_instance.py index 479e89f2..b538eec3 100644 --- a/discord/stage_instance.py +++ b/discord/stage_instance.py @@ -61,6 +61,10 @@ class StageInstance(Hashable): Returns the stage instance's hash. + .. describe:: int(x) + + Returns the stage instance's ID. + Attributes ----------- id: :class:`int` diff --git a/discord/sticker.py b/discord/sticker.py index b0b5c678..8ec2ad01 100644 --- a/discord/sticker.py +++ b/discord/sticker.py @@ -67,6 +67,14 @@ class StickerPack(Hashable): Returns the name of the sticker pack. + .. describe:: hash(x) + + Returns the hash of the sticker pack. + + .. describe:: int(x) + + Returns the ID of the sticker pack. + .. describe:: x == y Checks if the sticker pack is equal to another sticker pack. diff --git a/discord/threads.py b/discord/threads.py index 892910d9..6f8ffb00 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -74,6 +74,10 @@ class Thread(Messageable, Hashable): Returns the thread's hash. + .. describe:: int(x) + + Returns the thread's ID. + .. describe:: str(x) Returns the thread's name. @@ -748,6 +752,10 @@ class ThreadMember(Hashable): Returns the thread member's hash. + .. describe:: int(x) + + Returns the thread member's ID. + .. describe:: str(x) Returns the thread member's name. diff --git a/discord/user.py b/discord/user.py index 57c032ac..3fa090a9 100644 --- a/discord/user.py +++ b/discord/user.py @@ -96,6 +96,9 @@ class BaseUser(_UserTag): def __str__(self) -> str: return f'{self.name}#{self.discriminator}' + def __int__(self) -> int: + return self.id + def __eq__(self, other: Any) -> bool: return isinstance(other, _UserTag) and other.id == self.id @@ -415,6 +418,10 @@ class User(BaseUser, discord.abc.Messageable): Returns the user's name with discriminator. + .. describe:: int(x) + + Returns the user's ID. + Attributes ----------- name: :class:`str` diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index d1ed1ade..1aec6544 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -886,6 +886,10 @@ class Webhook(BaseWebhook): Returns the webhooks's hash. + .. describe:: int(x) + + Returns the webhooks's ID. + .. versionchanged:: 1.4 Webhooks are now comparable and hashable. diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index 5c85a036..62fb2d5f 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -475,6 +475,10 @@ class SyncWebhook(BaseWebhook): Returns the webhooks's hash. + .. describe:: int(x) + + Returns the webhooks's ID. + .. versionchanged:: 1.4 Webhooks are now comparable and hashable.