ApplicationCommand
Represents a Discord slash command.
Attributes
int
The application command's application's id.
None
, str
The command's description. It's length can be in range [2:100].
Set as None
for context commands.
Localized descriptions of the application command.
Set as None
for context commands.
int
The guild's identifier to which the command is bound to.
Set as 0
if the command is global.
int
The application command's id.
None | tuple<ApplicationCommandIntegrationContextType>
The places where the application command shows up. None
means all.
None | tuple<ApplicationIntegrationType>
The options where the application command can be integrated to.
str
The name of the command. It's length can be in range [1:32].
Localized names of the application command.
bool
Whether the application command is only allowed in nsfw channels.
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
.
The required permissions to use the application command inside of a guild.
The application command target's type describing where it shows up.
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
mention
Returns the application command's mention.
Returns
mention : str
partial
Returns whether the application command is partial.
Returns
partial : bool
Methods
(name, ...)
__new__Creates a new application command with the given parameters.
Parameter | Type | Optional | Keyword only | Default | Description |
---|---|---|---|---|---|
name |
| The name of the command. It's length can be in range [1:32]. | |||
description |
|
| The command's description. It's length can be in range [2:100]. Defaults to the | ||
description_localizations |
| Localized descriptions of the application command. | |||
integration_context_types |
| The places where the application command shows up. | |||
integration_types |
| The options where the application command can be integrated to. | |||
name_localizations |
| Localized names of the application command. | |||
nsfw |
| Whether the application command is allowed in nsfw channels. | |||
options |
| The parameters of the command. It's length can be in range [0:25]. | |||
required_permissions |
| The required permissions to use the application command inside of a guild. | |||
target_type |
| The application command's target type. Defaults to |
Raises
TypeError
- If a parameter's type is incorrect.
ValueError
- If a parameter's value is incorrect.
()
copyCopies the application command.
The copy is always a partial application command.
Returns
new : instance<type<self>>
()
copy_withCopies 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.
(data)
from_dataCreates a new Application command from the given data.
Parameter | Type | Description |
---|---|---|
data |
| Received application command data. |
Returns
self : instance<cls>
The created application command instance.
(integration_context_type)
has_integration_context_typeReturns whether the application command is allowed the given integration context type.
Parameter | Type | Description |
---|---|---|
integration_context_type | The integration_context type to check. |
Returns
hash_integration_context_type : bool
(integration_type)
has_integration_typeReturns whether the application command is allowed the given integration type.
Parameter | Type | Description |
---|---|---|
integration_type | The integration type to check. |
Returns
hash_integration_type : bool
()
is_context_commandReturns whether the application command is a context command.
Returns
is_context_command : bool
()
is_slash_commandReturns whether the application command is a slash command.
Returns
is_slash_command : bool
()
iter_integration_context_typesIterates over the integration context types that the application command is allowed for.
Yields
integration_context_type : ApplicationCommandIntegrationContextType
()
iter_integration_typesIterates over the integration types that the application command is allowed for.
Yields
integration_type : ApplicationIntegrationType
()
iter_optionsIterates over the options of the application command.
This method is an iterable generator.
Yields
option : ApplicationCommandOption
(...)
mention_sub_commandReturns the application command's mention extended with the given sub-command names..
Parameter | Type | Optional | Description |
---|---|---|---|
*sub_command_names |
| The sub commands' names to mention. |
Returns
mention : str
(with_)
mention_withReturns the application command's mention with the added string.
Parameter | Type | Description |
---|---|---|
with_ |
| Additional string to mention the command with. It should be sub commands' name. |
Returns
mention : str
(application_command_id, ...)
precreateCreates a new application command. If it already exists pick that up.
Parameter | Type | Optional | Keyword only | Default | Description |
---|---|---|---|---|---|
application_command_id |
| The application command's identifier. | |||
**keyword_parameters | Keyword parameters | Additional parameter to set the application command's fields with. | |||
application |
| Alternative for | |||
application_id |
| The application command's application's id. | |||
description |
|
| The command's description. It's length can be in range [2:100]. | ||
description_localizations |
| Localized descriptions of the application command. | |||
guild |
| Alternative for | |||
guild_id |
| The guild's identifier to which the command is bound to. | |||
integration_context_types |
| The places where the application command shows up. | |||
integration_types |
| The options where the application command can be integrated to. | |||
name |
| The name of the command. It's length can be in range [1:32]. | |||
name_localizations |
| Localized names of the application command. | |||
nsfw |
| Whether the application command is allowed in nsfw channels. | |||
options |
| The parameters of the command. It's length can be in range [0:25]. | |||
required_permissions |
| The required permissions to use the application command inside of a guild. | |||
target_type |
| The application command's target type. | |||
version |
| 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_dataConverts the application command to a json serializable object.
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
(translation_table, ...)
with_translationReturns a new application command with the given translation table applied.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
translation_table |
| Translation table to pull localization. from. | ||
replace |
|
| Whether actual translation should be replaced. |
Returns
new : instance<type<self>>
(application_command_id, application_id)
_create_emptyCreates an empty application command with the default attributes set.
Parameter | Type | Description |
---|---|---|
application_command_id |
| The application command's identifier. |
application_id |
| The application command's owner application's identifier. |
Returns
self : instance<cls>
(data)
_difference_update_attributesUpdates 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.
Parameter | Type | Description |
---|---|---|
data |
| 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:
Keys | Values |
---|---|
description | None , str |
description_localizations | None , dict of (Locale , str ) items |
integration_context_types | None , tuple of ApplicationCommandIntegrationContextType |
integration_types | None , tuple of ApplicationIntegrationType |
name | str |
name_localizations | None , dict of (Locale , str ) items |
nsfw | bool |
options | None , list of ApplicationCommandOption |
required_permissions | Permission |
target_type | ApplicationCommandTargetType |
version | int |
(data, application_command_id, application_id)
_from_edit_dataCreates an application command with the given parameters after an application command edition took place.
Parameter | Type | Description |
---|---|---|
data |
| Application command data returned by it's |
application_command_id |
| The unique identifier number of the newly created application command. |
application_id |
| The new application identifier number of the newly created application command. |
Returns
self : instance<cls>
The newly created or updated application command.
()
_get_hash_partialHashes the fields of the application command.
Called by .__hash__ when the application command is partial.
Returns
hash_value : int
(other)
_is_equal_same_typeReturns whether the two instances are equal.
Helper method for .__eq__
Parameter | Type | Description |
---|---|---|
other |
| The other instance. Must be from the same type. |
Returns
is_equal : bool
(data)
_update_attributesUpdates the application command with the given data.
Parameter | Type | Description |
---|---|---|
data |
| Received application command data. |
()
__eq__Returns whether the two application commands are equal.
(code)
__format__Formats the application command in a format string.
Parameter | Type | Description |
---|---|---|
code |
| 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.