Add __int__ special method to User and Member

This commit is contained in:
Arthur Jovart 2021-08-29 00:59:29 +02:00
parent 6bcc717e63
commit 31e3e99c2b
No known key found for this signature in database
GPG Key ID: DE4444AAAAAAAAAA
2 changed files with 14 additions and 0 deletions

View File

@ -226,6 +226,10 @@ class Member(discord.abc.Messageable, _UserTag):
Returns the member's name with the discriminator.
.. describe:: int(x)
Returns the user's ID.
Attributes
----------
joined_at: Optional[:class:`datetime.datetime`]
@ -300,6 +304,9 @@ class Member(discord.abc.Messageable, _UserTag):
def __str__(self) -> str:
return str(self._user)
def __int__(self) -> int:
return self.id
def __repr__(self) -> str:
return (
f'<Member id={self._user.id} name={self._user.name!r} discriminator={self._user.discriminator!r}'

View File

@ -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`