Webhook

Represents a Discord webhook. At some cases it might be used as webhook's user representation.

Attributes

application_id : int

The application's identifier what created the webhook. Defaults to 0 if not applicable.

avatar_hash : int

The webhook's avatar's hash in uint128.

avatar_type : IconType

The webhook's avatar's type.

channel_id : int

The channel's identifier, where the webhook is going to send it's messages.

id : int

The webhook's unique identifier number.

name : str

The webhook's name.

source_channel : None, WebhookSourceChannel

Representation of the webhook's source channel. Applicable for WebhookType.server webhooks.

source_guild : None, WebhookSourceGuild

Representation of the webhook's source guild. Applicable for WebhookType.server webhooks.

token : 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

Returns the user's top activity if applicable. If not.

Returns

activity : Activity, None

avatar

Returns the respective icon.

Returns

icon : Icon

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

Returns the webhook's channel if applicable.

Returns

channel : Channel

created_at

When the entity was created.

Returns

created_at : datetime

custom_activity

Returns the user's custom activity if applicable.

Returns

activity : Activity, None

default_avatar

Returns the user's default avatar.

Returns

default_avatar : DefaultAvatar

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

Returns the webhook's guild if applicable.

Returns

guild : None, 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

Returns the webhook's url.

This function is a shared property of Webhook-s.

Returns

url : str

Methods

__new__(...)

Creates a new partial webhook base with the given fields.

ParameterTypeOptionalKeyword onlyDescription
application_id

int, Application

The application's identifier what created the webhook.

channel_id

int

The channel's identifier, where the webhook is going to send it's messages.

avatar

None, Icon, str, bytes-like

The user's avatar.

source_channel

None, WebhookSourceChannel

Representation of the webhook's source channel.

source_guild

None, WebhookSourceGuild

Representation of the webhook's source guild.

name

str

The user's name.

token

str

The webhook's token.

user

ClientUserBase

The creator of the webhook.

webhook_type

WebhookType, int

The webhook's type.

Raises

TypeError

  • If a parameter's type is incorrect.

ValueError

  • If a parameter's value is incorrect.

avatar_decoration_url_as(...)

Returns the user's avatar decoration's url. If the user has no avatar decoration returns None.

This function is a method of UserBase.

ParameterTypeOptionalDefaultDescription
ext

None, str

None

The extension of the image's url. Can be any of: png.

size

None, int

None

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_as(...)

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 method of UserBase-s.

ParameterTypeOptionalDefaultDescription
ext

None, str

None

The extension of the image's url. Can be any of: 'jpg', 'jpeg', 'png', 'webp'. If the user has animated avatar, it can 'gif' as well.

size

None, int

None

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.

avatar_url_at(guild)

Returns the user's avatar's url at the guild.

This function is a shared method of UserBase-s.

ParameterTypeDescription
guild

Guild, int

The respective guild or it's identifier.

Returns

url : None, str

avatar_url_at_as(guild, ...)

Returns 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.

ParameterTypeOptionalDefaultDescription
guild

Guild, int

The respective guild or it's identifier.

ext

None, str

None

The extension of the image's url. Can be any of: 'jpg', 'jpeg', 'png', 'webp'. If the user has animated avatar, it can 'gif' as well.

size

None, int

None

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.

avatar_url_for(guild)

Returns 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.

ParameterTypeDescription
guild

Guild, int

The respective guild or it's identifier.

Returns

url : None, str

avatar_url_for_as(guild, ...)

Returns 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.

ParameterTypeOptionalDefaultDescription
guild

Guild, int

The respective guild or it's identifier.

ext

None, str

None

The extension of the image's url. Can be any of: 'jpg', 'jpeg', 'png', 'webp'. If the user has animated avatar, it can 'gif' as well.

size

None, int

None

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_as(...)

Returns the user's banner's url. If the user has no banner, then returns None.

This function is a shared method of UserBase-s.

ParameterTypeOptionalDefaultDescription
ext

None, str

None

The extension of the image's url. Can be any of: 'jpg', 'jpeg', 'png', 'webp'. If the user has animated banner, it can 'gif' as well.

size

None, int

None

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.

can_use_emoji(emoji)

Returns whether the user can use the given emoji.

ParameterTypeDescription
emoji

Emoji

The emoji to check.

Returns

can_use_emoji : bool

color_at(guild)

Returns the user's color at the given guild.

ParameterTypeDescription
guild

None, Guild, int

The guild, where the user's color will be checked.

Can be given as None.

Returns

color : Color

copy()

Copies the user returning a new partial one.

Returns

new : instance<type<self>>

copy_with(...)

Copies the webhook base with the given fields.

ParameterTypeOptionalKeyword onlyDescription
application_id

int, Application

The application's identifier what created the webhook.

channel_id

int

The channel's identifier, where the webhook is going to send it's messages.

avatar

None, Icon, str, bytes-like

The user's avatar.

source_channel

None, WebhookSourceChannel

Representation of the webhook's source channel.

source_guild

None, WebhookSourceGuild

Representation of the webhook's source guild.

name

str

The user's name.

token

str

The webhook's token.

user

ClientUserBase

The creator of the webhook.

webhook_type

WebhookType, int

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.

from_data(data)

Tries 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.

ParameterTypeDescription
data

dict of (str, object) items

Received webhook data.

Returns

self : instance<cls>

from_url(url)

Tries to parse the webhook's id and token from the given url. If succeeds, returns a partial webhook. If parsing fails, returns None.

ParameterTypeDescription
url

str

The url of the webhook.

Returns

self : None, instance<cls>

get_guild_profile_for(guild)

Returns the user's guild profile for the given guild.

ParameterTypeDescription
guild

None, Guild, int

The guild to get guild profile for.

Returns

guild_profile : None, Guild

get_status_by_platform(platform)

Gets the user's status by the given platform.

ParameterTypeDescription
platform

str

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.

has_higher_role_than(role)

Returns 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.

ParameterTypeDescription
role

Role

The role to check.

Returns

has_higher_role_than : bool

has_higher_role_than_at(user, guild)

Returns whether the user has higher role as the other one at the given guild.

ParameterTypeDescription
user

User

The other user to check.

guild

Guild, None, int

The guild where the users' top roles will be checked.

Can be given as None.

Returns

has_higher_role_than_at : bool

has_name_like(name)

Returns whether the user's name is like the given string.

ParameterTypeDescription
name

str

The name of the user.

Returns

has_name_like : bool

has_name_like_at(name, guild)

Returns whether the user's name is like the given string.

ParameterTypeDescription
name

str

The name of the user.

guild

None, Guild, int

The guild, where the user's nick will be also checked.

Can be given as None.

Returns

has_name_like : bool

has_role(role)

Returns whether the user has the given role.

ParameterTypeDescription
role

Role

The role what will be checked.

Returns

has_role : bool

is_boosting(guild)

Returns whether the user is boosting the given guild.

ParameterTypeDescription
guild

None, Guild, int

The guild to get whether the user is booster of.

Returns

is_boosting : bool

iter_activities()

Iterates over the user's activities.

This method is an iterable generator.

Yields

activity : Activity

iter_guilds()

Iterates over the guilds of the user.

This method is an iterable generator.

Yields

guild : Guild

The guild profile's guild.

iter_guilds_and_profiles()

Iterates 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.

mentioned_in(message)

Returns whether the user is mentioned at a given message.

ParameterTypeDescription
message

Message

The message, what's mentions will be checked.

Returns

mentioned : bool

name_at(guild)

Returns the user's name at the given guild.

ParameterTypeDescription
guild

None, Guild, int

The guild, where the user's nick will be checked.

Can be given as None.

Returns

name : str

precreate(webhook_id, ...)

Precreates 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.

ParameterTypeOptionalKeyword onlyDescription
webhook_id

int, str

The webhook's id.

**keyword_parameters

keyword parameters

Additional predefined attributes for the webhook.

application

int, Application

Alternative for application_id.

application_id

int, Application

The application's identifier what created the webhook.

avatar

None, Icon, str

The webhook's avatar.

channel

int, Channel

Alternative for channel_id.

channel_id

int, Channel

The channel's identifier, where the webhook is going to send it's messages.

name

str

The webhook's name.

source_channel

None, WebhookSourceChannel

Representation of the webhook's source channel.

source_guild

None, WebhookSourceGuild

Representation of the webhook's source guild.

token

str

The webhook's token.

user

ClientUserBase

The creator of the webhook.

webhook_type

WebhookType, int

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_data(...)

Tries to convert the user back to a json serializable dictionary.

ParameterTypeOptionalKeyword onlyDefaultDescription
defaults

bool

False

Whether default values should be included as well.

include_internals

bool

False

Whether internal fields should be included as well.

Returns

data : dict of (str, object) items

to_webhook_data(...)

Tries to convert the webhook back to a json serializable dictionary.

ParameterTypeOptionalKeyword onlyDefaultDescription
defaults

bool

False

Whether default values should be included as well.

include_internals

bool

False

Whether internal fields should be included as well.

Returns

data : dict of (str, object) items

top_role_at(guild, ...)

Returns the top role of the user at the given guild.

ParameterTypeOptionalDefaultDescription
guild

None, Guild, int

The guild where the user's top role will be looked up.

default

object

None

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 None.

Returns

top_role Role, default

_compare_attributes(other)

Compares the two user's user attributes (excluding id obviously).

ParameterTypeDescription
other

instance<type<self>>

The other user.

Returns

is_equal : bool

_compare_user_attributes_extended(other)

Compares the two user's user attributes (excluding id obviously).

ParameterTypeDescription
other

instance<type<self>>

The other user.

Returns

is_equal : bool

_compare_webhook_attributes(other)

Compares the two user's webhook attributes (excluding id obviously).

ParameterTypeDescription
other

instance<type<self>>

The other user.

Returns

is_equal : bool

_create_empty(user_id)

Creates a user with its default attributes values set.

ParameterTypeDescription
user_id

int

The user's identifier.

Returns

self : instance<cls>

_delete()

Deletes the user from it's guilds.

_difference_update_attributes(data)

Updates the user and returns it's overwritten attributes as a dict with a attribute-name- old-value relation.

ParameterTypeDescription
data

dict of (str, object) items

User data received from Discord.

Returns

old_attributes : dict of (str, object) items

All item in the returned dict is optional.

Returned Data Structure

KeysValuesApplicable for
avatarIconall
avatar_decorationNone, AvatarDecorationClient, User
bannerIconClient, User
banner_colorNone, ColorClient, User
channel_idintWebhook
discriminatorintClient, User
display_nameNone, strClient, User
emailNone, strClient
email_verifiedboolClient
flagsUserFlagClient, User
localeLocaleClient
mfa_enabledboolClient
namestrall
premium_typePremiumTypeClient

_difference_update_presence(data)

Updates 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.

ParameterTypeDescription
data

dict of (str, object) items

Received guild member data.

Returns

old_attributes : dict of (str, object) items

All item in the returned dict is optional.

Returned Data Structure

KeysValues
activitiesActivityChange
statusStatus
statusesNone, dict of (str, str) items

_difference_update_profile(data, guild)

Tries to find the user's respective guild profile. If it cannot find it, creates it.

ParameterTypeDescription
data

dict<str, object>

Received guild profile data.

guild

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:

KeysValues
avatarIcon
boosts_sinceNone, DateTime
flagsNone, GuildProfileFlags
nickNone, str
pendingbool
role_idsNone, tuple of int
timed_out_untilNone, DateTime

_from_data_and_difference_update_profile(data, guild)

First 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.

ParameterTypeDescription
data

dict<str, object>

Received guild member data.

guild

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:

KeysValues
avatarIcon
boosts_sinceNone, DateTime
flagsNone, GuildProfileFlags
nickNone, str
pendingbool
role_idsNone, tuple of int
timed_out_untilNone, DateTime

_from_data_and_update_profile(data, guild)

First 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.

ParameterTypeDescription
data

dict<str, object>

Received guild member data.

guild

Guild

The respective guild of the profile to update.

Returns

user : ClientUserbase

The updated user.

_from_follow_data(data, source_channel, target_channel_id, client)

Creates the webhook, what executes cross-posts.

This method is ensured after following a channel.

This method is a coroutine.

ParameterTypeDescription
data

dict of (str, object) items

Received webhook data.

source_channel

Channel

The followed channel.

target_channel_id

int

The target channel's identifier where the webhook messages will be sent.

client

Client

The client who created the webhook.

Returns

self : instance<cls>

_get_hash_partial()

Returns a partial user's hash value.

Returns

hash_value : int

_is_equal_same_type(other)

Returns whether the two users are equal. self and other must be the same type.

ParameterTypeDescription
other

instance<type<self>>

The other user.

Returns

is_equal : bool

_set_attributes(data)

Sets 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.

ParameterTypeDescription
data

dict of (str, object) items

Received webhook data.

_set_default_attributes()

Sets the user's attribute's to their default.

_update_attributes(data)

Updates the user with the given data by overwriting it's old attributes.

ParameterTypeDescription
data

dict of (str, object) items

User data received from Discord.

_update_presence(data)

Updates the user's presences with the given data.

ParameterTypeDescription
data

dict of (str, object) items

Received guild member data.

_update_profile(data, guild)

Tries to find the user's respective guild profile. If it cannot find it, creates it.

ParameterTypeDescription
data

dict<str, object>

Received guild profile data.

guild

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.

__format__(code)

Formats the user in a format string.

ParameterTypeDescription
code

str

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.