Webhook
Represents a Discord webhook. At some cases it might be used as webhook's user representation.
Attributes
int
The application's identifier what created the webhook. Defaults to 0
if not applicable.
int
The webhook's avatar's hash in uint128
.
The webhook's avatar's type.
int
The channel's identifier, where the webhook is going to send it's messages.
int
The webhook's unique identifier number.
The webhook's name.
None
, WebhookSourceChannel
Representation of the webhook's source channel. Applicable for WebhookType.server
webhooks.
None
, WebhookSourceGuild
Representation of the webhook's source guild. Applicable for WebhookType.server
webhooks.
str
The webhook's token. You need an id
and a token
to send webhook message. Defaults to empty string.
The webhook's type.
The creator of the webhook, or ZEROUSER
if unknown.
Notes
Instances of this class are weakreferable.
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_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
bot
Webhooks are always bots.
Returns
bot : bool
channel
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
guild
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 webhook is partial.
A webhook is partial, if it's respective guild is unknown.
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
url
Methods
(...)
__new__Creates a new partial webhook base with the given fields.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
application_id |
| The application's identifier what created the webhook. | ||
channel_id |
| The channel's identifier, where the webhook is going to send it's messages. | ||
avatar |
| The user's avatar. | ||
source_channel |
| Representation of the webhook's source channel. | ||
source_guild |
| Representation of the webhook's source guild. | ||
name |
| The user's name. | ||
token |
| The webhook's token. | ||
user | The creator of the webhook. | |||
webhook_type |
| The webhook's type. |
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 webhook base with the given fields.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
application_id |
| The application's identifier what created the webhook. | ||
channel_id |
| The channel's identifier, where the webhook is going to send it's messages. | ||
avatar |
| The user's avatar. | ||
source_channel |
| Representation of the webhook's source channel. | ||
source_guild |
| Representation of the webhook's source guild. | ||
name |
| The user's name. | ||
token |
| The webhook's token. | ||
user | The creator of the webhook. | |||
webhook_type |
| The webhook's type. |
Returns
new : instance<type<self>>
Raises
TypeError
- If a parameter's type is incorrect.
ValueError
- If a parameter's value is incorrect.
(data)
from_dataTries to get the webhook from the existing ones, then update it. If no webhook was found, creates a new one and fills it's attributes from the data.
Parameter | Type | Description |
---|---|---|
data |
| Received webhook data. |
Returns
self : instance<cls>
(url)
from_urlTries to parse the webhook's id
and token
from the given url
. If succeeds, returns a partial webhook. If parsing fails, returns None
.
Parameter | Type | Description |
---|---|---|
url |
| The url of the webhook. |
Returns
self : None
, 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
(webhook_id, ...)
precreatePrecreates the webhook by creating a partial one with the given parameters. When the webhook will be loaded, the precreated one will be picked up and will be updated. If an already existing webhook would be precreated, it will be updated with the given parameters only if it is a partial one.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
webhook_id |
| The webhook's id. | ||
**keyword_parameters | keyword parameters | Additional predefined attributes for the webhook. | ||
application |
| Alternative for | ||
application_id |
| The application's identifier what created the webhook. | ||
avatar |
| The webhook's avatar. | ||
channel |
| Alternative for | ||
channel_id |
| The channel's identifier, where the webhook is going to send it's messages. | ||
name |
| The webhook's name. | ||
source_channel |
| Representation of the webhook's source channel. | ||
source_guild |
| Representation of the webhook's source guild. | ||
token |
| The webhook's token. | ||
user | The creator of the webhook. | |||
webhook_type |
| The webhook's type. |
Returns
self : instance<cls>
Raises
TypeError
- If a parameter's type is incorrect.
ValueError
- If a parameter's value is incorrect.
(...)
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
(...)
to_webhook_dataTries to convert the webhook 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
(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
(other)
_compare_webhook_attributesCompares the two user's webhook 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 |
(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.
(data, source_channel, target_channel_id, client)
_from_follow_dataCreates the webhook, what executes cross-posts.
This method is ensured after following a channel.
This method is a coroutine.
Parameter | Type | Description |
---|---|---|
data |
| Received webhook data. |
source_channel | The followed channel. | |
target_channel_id |
| The target channel's identifier where the webhook messages will be sent. |
client | The client who created the webhook. |
Returns
self : instance<cls>
()
_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
(data)
_set_attributesSets the webhook's attributes from the given data.
Not like ._update_attributes
, this method also sets the attributes that are not expected to be modified.
Parameter | Type | Description |
---|---|---|
data |
| Received webhook data. |
()
_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.