ClientUserBase
Base class for discord users and clients.
Attributes
None
, AvatarDecoration
The user's avatar decorations.
int
The user's avatar's hash in uint128
.
The user's avatar's type.
None
, Color
The user's banner color if has any.
int
The user's banner's hash in uint128
.
The user's banner's type.
bool
Whether the user is a bot or a user account.
int
The user's discriminator. Given to avoid overlapping names.
None
, str
The user's non-unique display name.
The user's user flags.
A dictionary, which contains the user's guild profiles. If a user is member of a guild, then it should have a respective guild profile accordingly.
int
The user's unique identifier number.
The user's name.
A Dictionary which contains the thread profiles for the user in thread channel - thread profile relation. Defaults to None
.
Properties
activity
avatar
avatar_decoration_url
Returns the user's avatar decoration's url. If the user has no avatar decoration returns None
.
This function is a property of UserBase
.
Returns
url : None
, str
avatar_url
Returns the user's avatar's url. If the user has no avatar, then returns it's default avatar's url.
This function is a shared property of UserBase
-s.
Returns
url : None
, str
banner
banner_url
Returns the user's banner's url. If the user has no banner, then returns None
.
This function is a shared property of UserBase
-s.
Returns
url : None
, str
created_at
When the entity was created.
Returns
created_at : datetime
custom_activity
default_avatar
default_avatar_url
Returns the user's default avatar's url.
Returns
default_avatar_url : str
full_name
The user's name with it's discriminator.
Returns
full_name : str
mention
The mention of the user.
Returns
mention : str
mention_nick
The mention to the user's nick.
Returns
mention : str
Notes
It actually has nothing to do with the user's nickname > <.
mfa
Returns whether the user has multi factory authentication enabled.
This property is deprecated and will be removed in 2024 April. Please use mfa_enabled
instead.
Returns
mfa_enabled : bool
partial
Returns whether the user is partial. Partial users have only their .id
set and every other field might not reflect the reality.
Returns
partial : bool
platform
Returns the user's top status's platform. If the user is offline it will return an empty string.
Returns
platform : str
Methods
(...)
__new__Creates a new partial user with the given fields.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
avatar |
| The user's avatar. | ||
avatar_decoration |
| The user's avatar decoration. | ||
banner |
| The user's banner. | ||
banner_color |
| The user's banner color. | ||
bot |
| Whether the user is a bot or a user account. | ||
discriminator |
| The user's discriminator. | ||
display_name |
| The user's non-unique display name. | ||
flags |
| The user's flags. | ||
name |
| The user's name. |
Raises
TypeError
- If a parameter's type is incorrect.
ValueError
- If a parameter's value is incorrect.
(...)
avatar_decoration_url_asReturns the user's avatar decoration's url. If the user has no avatar decoration returns None
.
This function is a method of UserBase
.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
ext |
|
| The extension of the image's url. Can be any of: | |
size |
|
| The preferred minimal size of the image's url. |
Returns
url : None
, str
Raises
ValueError
If ext
, size
was not passed as any of the expected values.
(...)
avatar_url_asReturns the user's avatar's url. If the user has no avatar, then returns it's default avatar's url.
This function is a shared method of UserBase
-s.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
ext |
|
| The extension of the image's url. Can be any of: | |
size |
|
| The preferred minimal size of the avatar's url. |
Returns
url : None
, str
Raises
ValueError
If ext
, size
was not passed as any of the expected values.
(guild)
avatar_url_atReturns the user's avatar's url at the guild.
This function is a shared method of UserBase
-s.
Parameter | Type | Description |
---|---|---|
guild |
| The respective guild or it's identifier. |
Returns
url : None
, str
(guild, ...)
avatar_url_at_asReturns the user's avatar's url at the guild. If the user has no avatar, then returns it's default avatar's url.
This function is a shared method of UserBase
-s.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
guild |
| The respective guild or it's identifier. | ||
ext |
|
| The extension of the image's url. Can be any of: | |
size |
|
| The preferred minimal size of the avatar's url. |
Returns
url : None
, str
Raises
ValueError
If ext
, size
was not passed as any of the expected values.
(guild)
avatar_url_forReturns the user's guild specific avatar. If the user has no guild local avatar, returns None
.
This function is a shared method of UserBase
-s.
Parameter | Type | Description |
---|---|---|
guild |
| The respective guild or it's identifier. |
Returns
url : None
, str
(guild, ...)
avatar_url_for_asReturns the user's guild specific avatar. If the user has no guild local avatar, then returns None
.
This function is a shared method of UserBase
-s.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
guild |
| The respective guild or it's identifier. | ||
ext |
|
| The extension of the image's url. Can be any of: | |
size |
|
| The preferred minimal size of the avatar's url. |
Returns
url : None
, str
Raises
ValueError
If ext
, size
was not passed as any of the expected values.
(...)
banner_url_asReturns the user's banner's url. If the user has no banner, then returns None
.
This function is a shared method of UserBase
-s.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
ext |
|
| The extension of the image's url. Can be any of: | |
size |
|
| The preferred minimal size of the avatar's url. |
Returns
url : None
, str
Raises
ValueError
If ext
, size
was not passed as any of the expected values.
(emoji)
can_use_emojiReturns whether the user can use the given emoji.
Parameter | Type | Description |
---|---|---|
emoji | The emoji to check. |
Returns
can_use_emoji : bool
(guild)
color_atReturns the user's color at the given guild.
Parameter | Type | Description |
---|---|---|
guild |
| The guild, where the user's color will be checked. Can be given as |
Returns
color : Color
()
copyCopies the user returning a new partial one.
Returns
new : instance<type<self>>
(...)
copy_withCopies the user with the given fields.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
avatar |
| The user's avatar. | ||
avatar_decoration |
| The user's avatar decoration. | ||
banner |
| The user's banner. | ||
banner_color |
| The user's banner color. | ||
bot |
| Whether the user is a bot or a user account. | ||
discriminator |
| The user's discriminator. | ||
display_name |
| The user's non-unique display name. | ||
flags |
| The user's flags. | ||
name |
| The user's name. |
Returns
new : instance<type<self>>
Raises
TypeError
- If a parameter's type is incorrect.
ValueError
- If a parameter's value is incorrect.
(user_data, ...)
from_dataCreates a new user from the given data.
Parameter | Type | Optional | Keyword only | Default | Description |
---|---|---|---|---|---|
user_data |
| User data. | |||
guild_profile_data |
|
| Guild profile data. | ||
guild_id |
|
| The guild's identifier to which the guild profile is bound to. | ||
strong_cache |
|
| Whether the instance should be put into its strong cache. |
Returns
self : instance<cls>
(guild)
get_guild_profile_forReturns the user's guild profile for the given guild.
Parameter | Type | Description |
---|---|---|
guild |
| The guild to get guild profile for. |
Returns
guild_profile : None
, Guild
(platform)
get_status_by_platformGets the user's status by the given platform.
Parameter | Type | Description |
---|---|---|
platform |
| The platform to get the status for. |
Returns
status : Status
Defaults to status.offline
if the user has no specific status for the given platform.
(role)
has_higher_role_thanReturns whether the user has higher role than the given role at it's respective guild.
If the user is the owner of the guild, then returns True
even if it has lower role.
Parameter | Type | Description |
---|---|---|
role | The role to check. |
Returns
has_higher_role_than : bool
(user, guild)
has_higher_role_than_atReturns whether the user has higher role as the other one at the given guild.
Parameter | Type | Description |
---|---|---|
user | The other user to check. | |
guild |
| The guild where the users' top roles will be checked. Can be given as |
Returns
has_higher_role_than_at : bool
(name)
has_name_likeReturns whether the user's name is like the given string.
Parameter | Type | Description |
---|---|---|
name |
| The name of the user. |
Returns
has_name_like : bool
(name, guild)
has_name_like_atReturns whether the user's name is like the given string.
Parameter | Type | Description |
---|---|---|
name |
| The name of the user. |
guild |
| The guild, where the user's nick will be also checked. Can be given as |
Returns
has_name_like : bool
(role)
has_roleReturns whether the user has the given role.
Parameter | Type | Description |
---|---|---|
role | The role what will be checked. |
Returns
has_role : bool
(guild)
is_boostingReturns whether the user is boosting the given guild.
Parameter | Type | Description |
---|---|---|
guild |
| The guild to get whether the user is booster of. |
Returns
is_boosting : bool
()
iter_activities()
iter_guildsIterates over the guilds of the user.
This method is an iterable generator.
Yields
guild : Guild
The guild profile's guild.
()
iter_guilds_and_profilesIterates over the guild profiles of the user.
This method is an iterable generator.
Yields
guild : Guild
The guild profile's guild.
guild_profile : GuildProfile
The user's guild profile in the guild.
(message)
mentioned_inReturns whether the user is mentioned at a given message.
Parameter | Type | Description |
---|---|---|
message | The message, what's mentions will be checked. |
Returns
mentioned : bool
(guild)
name_atReturns the user's name at the given guild.
Parameter | Type | Description |
---|---|---|
guild |
| The guild, where the user's nick will be checked. Can be given as |
Returns
name : str
(...)
to_dataTries to convert the user back to a json serializable dictionary.
Parameter | Type | Optional | Keyword only | Default | Description |
---|---|---|---|---|---|
defaults |
|
| Whether default values should be included as well. | ||
include_internals |
|
| Whether internal fields should be included as well. |
Returns
data : dict
of (str
, object
) items
(guild, ...)
top_role_atReturns the top role of the user at the given guild.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
guild |
| The guild where the user's top role will be looked up. | ||
default |
|
| If the user is not a member of the guild, or if has no roles there, then the given default value is returned. Defaults to |
Returns
top_role Role
, default
(data, guild_profile_data, guild_id)
_bypass_no_cacheSets a Client
's guild profile.
Only available when user or presence caching is disabled.
Parameter | Type | Description |
---|---|---|
data |
| Received user data. |
guild_profile_data |
| The user's guild profile's data. |
guild_id |
| A respective guild's identifier from where the user data was received. Picked up if the given data includes guild member data as well. |
Returns
user : ClientUserBase
(other)
_compare_attributesCompares the two user's user attributes (excluding id obviously).
Parameter | Type | Description |
---|---|---|
other |
| The other user. |
Returns
is_equal : bool
(other)
_compare_user_attributes_extendedCompares the two user's user attributes (excluding id obviously).
Parameter | Type | Description |
---|---|---|
other |
| The other user. |
Returns
is_equal : bool
(user_id)
_create_emptyCreates a user with its default attributes values set.
Parameter | Type | Description |
---|---|---|
user_id |
| The user's identifier. |
Returns
self : instance<cls>
()
_deleteDeletes the user from it's guilds.
(data)
_difference_update_attributesUpdates the user and returns it's overwritten attributes as a dict
with a attribute-name
- old-value
relation.
Parameter | Type | Description |
---|---|---|
data |
| User data received from Discord. |
Returns
old_attributes : dict
of (str
, object
) items
All item in the returned dict is optional.
Returned Data Structure
Keys | Values | Applicable for |
---|---|---|
avatar | Icon | all |
avatar_decoration | None , AvatarDecoration | Client , User |
banner | Icon | Client , User |
banner_color | None , Color | Client , User |
channel_id | int | Webhook |
discriminator | int | Client , User |
display_name | None , str | Client , User |
None , str | Client | |
email_verified | bool | Client |
flags | UserFlag | Client , User |
locale | Locale | Client |
mfa_enabled | bool | Client |
name | str | all |
premium_type | PremiumType | Client |
(data)
_difference_update_presenceUpdates the user's presence and returns it's overwritten attributes as a dict
with a attribute-name
- old-value
relation. An exception from this is activities
, because that's a ActivityChange
containing all the changes of the user's activities.
Parameter | Type | Description |
---|---|---|
data |
| Received guild member data. |
Returns
old_attributes : dict
of (str
, object
) items
All item in the returned dict is optional.
Returned Data Structure
Keys | Values |
---|---|
activities | ActivityChange |
status | Status |
statuses | None , dict of (str , str ) items |
(data, guild)
_difference_update_profileTries to find the user's respective guild profile. If it cannot find it, creates it.
Parameter | Type | Description |
---|---|---|
data |
| Received guild profile data. |
guild | The respective guild of the profile to update. |
Returns
old_attributes : None | dict<str, object>
The changed attributes of the respective guild profile as a dict
with attribute-name
- old-attribute
relation.
May return None
indicating that the guild profile was not cached before so we cannot determine whether it would have been updated.
The possible keys and values within old_attributes
are all optional and they can be any of the following:
Keys | Values |
---|---|
avatar | Icon |
boosts_since | None , DateTime |
flags | None , GuildProfileFlags |
nick | None , str |
pending | bool |
role_ids | None , tuple of int |
timed_out_until | None , DateTime |
(client, include_internals)
_from_clientCreates a client alter ego.
Parameter | Type | Description |
---|---|---|
client | The client to copy. | |
include_internals |
| Whether internal fields should be copied as well. |
Returns
user : ClientUserBase
(data, guild)
_from_data_and_difference_update_profileFirst tries to find the user, then it's respective guild profile for the given guild to update it.
If the method cannot find the user, or the respective guild profile, then creates them.
Parameter | Type | Description |
---|---|---|
data |
| Received guild member data. |
guild | The respective guild of the profile to update. |
Returns
user : ClientUserBase
The respective user.
old_attributes : None | dict<str, object>
The changed attributes of the respective guild profile as a dict
with attribute-name
- old-attribute
relation.
May return None
indicating that the guild profile was not cached before so we cannot determine whether it would have been updated.
The possible keys and values within old_attributes
are all optional and they can be any of the following:
Keys | Values |
---|---|
avatar | Icon |
boosts_since | None , DateTime |
flags | None , GuildProfileFlags |
nick | None , str |
pending | bool |
role_ids | None , tuple of int |
timed_out_until | None , DateTime |
(data, guild)
_from_data_and_update_profileFirst tries to find the user, then it's respective guild profile for the given guild to update it.
If the method cannot find the user, or the respective guild profile, then creates them.
Not like ._from_data_and_difference_update_profile
, this method not calculates changes.
Parameter | Type | Description |
---|---|---|
data |
| Received guild member data. |
guild | The respective guild of the profile to update. |
Returns
user : ClientUserbase
The updated user.
()
_get_hash_partialReturns a partial user's hash value.
Returns
hash_value : int
(other)
_is_equal_same_typeReturns whether the two users are equal. self
and other
must be the same type.
Parameter | Type | Description |
---|---|---|
other |
| The other user. |
Returns
is_equal : bool
()
_set_default_attributesSets the user's attribute's to their default.
(data)
_update_attributesUpdates the user with the given data by overwriting it's old attributes.
Parameter | Type | Description |
---|---|---|
data |
| User data received from Discord. |
(data)
_update_presenceUpdates the user's presences with the given data.
Parameter | Type | Description |
---|---|---|
data |
| Received guild member data. |
(data, guild)
_update_profileTries to find the user's respective guild profile. If it cannot find it, creates it.
Parameter | Type | Description |
---|---|---|
data |
| Received guild profile data. |
guild | The respective guild of the profile to update. |
Returns
updated : bool
Returns True
if the guild profile was updated and False
when created.
()
__eq__Return whether the user's id is equal to the other.
(code)
__format__Formats the user in a format string.
Parameter | Type | Description |
---|---|---|
code |
| The option on based the result will be formatted. |
Returns
user : str
Raises
ValueError
Unknown format code.
Examples
>>> from hata import User, now_as_id
>>> user = User.precreate(now_as_id(), name = 'Neko', discriminator = 2012)
>>> user
<User id = 730233383967260672, name = 'Neko#2012'>
>>> # no code stands for `user.name`.
>>> f'{user}'
'Neko'
>>> # 'f' stands for full name
>>> f'{user:f}'
'Neko#2012'
>>> # 'm' stands for mention.
>>> f'{user:m}'
'<@730233383967260672>'
>>> # 'c' stands for created at.
>>> f'{user:c}'
'2020.07.08-01:26:45'
()
__ge__Returns whether the user's id is greater or equal to the other.
()
__getattr__Drops a rich attribute error.
()
__gt__Returns whether the user's id is greater than the other's.
()
__hash__Returns the user's hash.
()
__le__Returns whether the user's id is less or equal to the other.
()
__lt__Returns whether the user's id is less than the other's.
()
__ne__Returns whether the user's id is different as the other's.
()
__repr__Returns the user's representation.