ApplicationCommand

Represents a Discord slash command.

Attributes

application_id : int

The application command's application's id.

description : None, str

The command's description. It's length can be in range [2:100].

Set as None for context commands.

description_localizations : None, dict of (Locale, str) items

Localized descriptions of the application command.

Set as None for context commands.

guild_id : int

The guild's identifier to which the command is bound to.

Set as 0 if the command is global.

id : int

The application command's id.

integration_context_types : None | tuple<ApplicationCommandIntegrationContextType>

The places where the application command shows up. None means all.

integration_types : None | tuple<ApplicationIntegrationType>

The options where the application command can be integrated to.

name : str

The name of the command. It's length can be in range [1:32].

name_localizations : None, dict of (Locale, str) items

Localized names of the application command.

nsfw : bool

Whether the application command is only allowed in nsfw channels.

options : None, tuple of ApplicationCommandOption

The parameters of the command. It's length can be in range [0:25]. If would be set as empty list, instead is set as None.

required_permissions : Permission

The required permissions to use the application command inside of a guild.

The application command target's type describing where it shows up.

version : int

The time when the command was last edited in snowflake.

Notes

Application command instances are weakreferable.

Properties

allow_in_dm

Whether the command can be used in private (dm) channels.

Deprecated and will be removed in 2024 November.

created_at

When the entity was created.

Returns

created_at : datetime

display_name

Returns the application command's display name.

Returns

display_name : str

edited_at

Returns when the command was last edited / modified. If the command was not edited yet, returns None.

Returns

edited_at : None, edited_at

guild

Returns the application command's guild.

Returns

guild : None, Guild

mention

Returns the application command's mention.

Returns

mention : str

partial

Returns whether the application command is partial.

Returns

partial : bool

Methods

__new__(name, ...)

Creates a new application command with the given parameters.

ParameterTypeOptionalKeyword onlyDefaultDescription
name

str

The name of the command. It's length can be in range [1:32].

description

None, str

None

The command's description. It's length can be in range [2:100].

Defaults to the name parameter if not given.

description_localizations

None, dict of ((str, Locale), str) items, (list, set, tuple) of tuple((str, Locale), str)

Localized descriptions of the application command.

integration_context_types

None | iterable<ApplicationCommandIntegrationContextType | int>

The places where the application command shows up. None means all.

integration_types

None | iterable<ApplicationIntegrationType | int>

The options where the application command can be integrated to.

name_localizations

None, dict of ((str, Locale), str) items, (list, set, tuple) of tuple((str, Locale), str)

Localized names of the application command.

nsfw

None, bool

Whether the application command is allowed in nsfw channels.

options

None, iterable of ApplicationCommandOption

The parameters of the command. It's length can be in range [0:25].

required_permissions

None, Permission, int

The required permissions to use the application command inside of a guild.

target_type

None, int, ApplicationCommandTargetType

The application command's target type.

Defaults to ApplicationCommandTargetType.chat.

Raises

TypeError

  • If a parameter's type is incorrect.

ValueError

  • If a parameter's value is incorrect.

copy()

Copies the application command.

The copy is always a partial application command.

Returns

new : instance<type<self>>

copy_with()

Copies the application command with the given fields.

Parameters description : None, str = None, Optional

The command's description. It's length can be in range [2:100].

description_localizations : None, dict of ((str, Locale), str) items, (list, set, tuple) of tuple((str, Locale), str), Optional (Keyword only)

Localized descriptions of the application command.

integration_context_types : None | iterable<ApplicationCommandIntegrationContextType | int>, Optional (Keyword only)

The places where the application command shows up. None means all.

integration_types : None | iterable<ApplicationIntegrationType | int>, Optional (Keyword only)

The options where the application command can be integrated to.

name : str, Optional (Keyword only)

The name of the command. It's length can be in range [1:32].

name_localizations : None, dict of ((str, Locale), str) items, (list, set, tuple) of tuple((str, Locale), str), Optional (Keyword only)

Localized names of the application command.

nsfw : None, bool, Optional (Keyword only)

Whether the application command is allowed in nsfw channels.

options : None, iterable of ApplicationCommandOption, Optional (Keyword only)

The parameters of the command. It's length can be in range [0:25].

required_permissions : None, Permission, int, Optional (Keyword only)

The required permissions to use the application command inside of a guild.

target_type : None, int, ApplicationCommandTargetType, Optional (Keyword only)

The application command's target 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)

Creates a new Application command from the given data.

ParameterTypeDescription
data

dict of (str, object) items

Received application command data.

Returns

self : instance<cls>

The created application command instance.

has_integration_context_type(integration_context_type)

Returns whether the application command is allowed the given integration context type.

ParameterTypeDescription
integration_context_type

int, ApplicationCommandIntegrationContextType

The integration_context type to check.

Returns

hash_integration_context_type : bool

has_integration_type(integration_type)

Returns whether the application command is allowed the given integration type.

ParameterTypeDescription
integration_type

int, ApplicationIntegrationType

The integration type to check.

Returns

hash_integration_type : bool

is_context_command()

Returns whether the application command is a context command.

Returns

is_context_command : bool

is_slash_command()

Returns whether the application command is a slash command.

Returns

is_slash_command : bool

iter_integration_context_types()

Iterates over the integration context types that the application command is allowed for.

Yields

integration_context_type : ApplicationCommandIntegrationContextType

iter_integration_types()

Iterates over the integration types that the application command is allowed for.

Yields

integration_type : ApplicationIntegrationType

iter_options()

Iterates over the options of the application command.

This method is an iterable generator.

Yields

option : ApplicationCommandOption

mention_sub_command(...)

Returns the application command's mention extended with the given sub-command names..

ParameterTypeOptionalDescription
*sub_command_names

str

The sub commands' names to mention.

Returns

mention : str

mention_with(with_)

Returns the application command's mention with the added string.

ParameterTypeDescription
with_

str

Additional string to mention the command with. It should be sub commands' name.

Returns

mention : str

precreate(application_command_id, ...)

Creates a new application command. If it already exists pick that up.

ParameterTypeOptionalKeyword onlyDefaultDescription
application_command_id

int

The application command's identifier.

**keyword_parameters

Keyword parameters

Additional parameter to set the application command's fields with.

application

int, Application

Alternative for application_id.

application_id

int, Application

The application command's application's id.

description

None, str

None

The command's description. It's length can be in range [2:100].

description_localizations

None, dict of ((str, Locale), str) items, (list, set, tuple) of tuple((str, Locale), str)

Localized descriptions of the application command.

guild

int, Guild

Alternative for guild_id.

guild_id

int, Guild

The guild's identifier to which the command is bound to.

integration_context_types

None | iterable<ApplicationCommandIntegrationContextType | int>

The places where the application command shows up. None means all.

integration_types

None | iterable<ApplicationIntegrationType | int>

The options where the application command can be integrated to.

name

str

The name of the command. It's length can be in range [1:32].

name_localizations

None, dict of ((str, Locale), str) items, (list, set, tuple) of tuple((str, Locale), str)

Localized names of the application command.

nsfw

None, bool

Whether the application command is allowed in nsfw channels.

options

None, iterable of ApplicationCommandOption

The parameters of the command. It's length can be in range [0:25].

required_permissions

None, Permission, int

The required permissions to use the application command inside of a guild.

target_type

None, int, ApplicationCommandTargetType

The application command's target type.

version

int

The time when the command was last edited in snowflake.

Returns

self : instance<cls>

Raises

TypeError

  • If a parameter's type is incorrect.

ValueError

  • If a parameter's value is incorrect.

to_data(...)

Converts the application command to a json serializable object.

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

with_translation(translation_table, ...)

Returns a new application command with the given translation table applied.

ParameterTypeOptionalDefaultDescription
translation_table

None, dict of ((Locale, str), (None, dict(str, (None, str)) items)) items

Translation table to pull localization. from.

replace

bool

False

Whether actual translation should be replaced.

Returns

new : instance<type<self>>

_create_empty(application_command_id, application_id)

Creates an empty application command with the default attributes set.

ParameterTypeDescription
application_command_id

int

The application command's identifier.

application_id

int

The application command's owner application's identifier.

Returns

self : instance<cls>

_difference_update_attributes(data)

Updates the application command with the given data and returns the updated attributes in a dictionary with the attribute names as the keys and their old value as the values.

ParameterTypeDescription
data

dict of (str, object) items

Received application command data.

Returns

old_attributes : dict of (str, object) items

The updated attributes.

Every item in the returned dict is optional and can contain the following ones:

KeysValues
descriptionNone, str
description_localizationsNone, dict of (Locale, str) items
integration_context_typesNone, tuple of ApplicationCommandIntegrationContextType
integration_typesNone, tuple of ApplicationIntegrationType
namestr
name_localizationsNone, dict of (Locale, str) items
nsfwbool
optionsNone, list of ApplicationCommandOption
required_permissionsPermission
target_typeApplicationCommandTargetType
versionint

_from_edit_data(data, application_command_id, application_id)

Creates an application command with the given parameters after an application command edition took place.

ParameterTypeDescription
data

dict of (str, object) items

Application command data returned by it's .to_data method.

application_command_id

int

The unique identifier number of the newly created application command.

application_id

int

The new application identifier number of the newly created application command.

Returns

self : instance<cls>

The newly created or updated application command.

_get_hash_partial()

Hashes the fields of the application command.

Called by .__hash__ when the application command is partial.

Returns

hash_value : int

_is_equal_same_type(other)

Returns whether the two instances are equal.

Helper method for .__eq__

ParameterTypeDescription
other

type<self>

The other instance. Must be from the same type.

Returns

is_equal : bool

_update_attributes(data)

Updates the application command with the given data.

ParameterTypeDescription
data

dict of (str, object) items

Received application command data.

__eq__()

Returns whether the two application commands are equal.

__format__(code)

Formats the application command in a format string.

ParameterTypeDescription
code

str

The option on based the result will be formatted.

Returns

application_command : str

Raises

ValueError

Unknown format code.

Examples

>>> from hata import ApplicationCommand
>>> application_command = ApplicationCommand('cake-lover', 'Sends a random cake recipe OwO')
>>> application_command
<ApplicationCommand partial name = 'cake-lover', description = 'Sends a random cake recipe OwO'>
>>> # no code stands for `application_command.name`.
>>> f'{application_command}'
'CakeLover'
>>> # 'd' stands for display name.
>>> f'{application_command:d}'
'cake-lover'
>>> # 'm' stands for mention.
>>> f'{application_command:m}'
'</cake-lover:0>'
>>> # To mention a sub command, use @sub-command's name.
>>> f'{application_command:m@eat}'
'</cake-lover eat:0>'
>>> # 'c' stands for created at.
>>> f'{application_command:c}'
'2021-01-03 20:17:36'
>>> # 'e' stands for edited at.
>>> f'{application_command:e}'
'never'

__ge__()

Whether this entity's id is greater or equal than the other's.

__getattr__()

Drops a rich attribute error.

__gt__()

Whether this entity's id is greater than the other's.

__hash__()

Returns the application's hash value.

__le__()

Whether this entity's id is less or equal than the other's.

__len__()

Returns the application command's length.

__lt__()

Whether this entity's id is less than the other's.

__ne__()

Returns whether the two application commands are different.

__repr__()

Returns the application command's representation.