Application Commands¶
This section documents everything related to Discord’s application commands.
Discord Models¶
APISlashCommand¶
- defadd_option
- class disnake.APISlashCommand[source]¶
A slash command returned by the API.
New in version 2.4.
- name_localizations¶
Localizations for
name
.New in version 2.5.
- Type:
- description_localizations¶
Localizations for
description
.New in version 2.5.
- Type:
- nsfw¶
Whether this command is age-restricted.
New in version 2.8.
- Type:
- install_types¶
The installation types where the command is available. Defaults to
ApplicationInstallTypes.guild
only. Only available for global commands.New in version 2.10.
- Type:
Optional[
ApplicationInstallTypes
]
- contexts¶
The interaction contexts where the command can be used. Only available for global commands.
New in version 2.10.
- Type:
Optional[
InteractionContextTypes
]
- guild_id¶
The ID of the guild this slash command is enabled in, or
None
if it’s global.- Type:
Optional[
int
]
- add_option(name, description=None, type=None, required=False, choices=None, options=None, channel_types=None, autocomplete=False, min_value=None, max_value=None, min_length=None, max_length=None)[source]¶
Adds an option to the current list of options, parameters are the same as for
Option
- property default_member_permissions[source]¶
The default required member permissions for this command. A member must have all these permissions to be able to invoke the command in a guild.
This is a default value, the set of users/roles that may invoke this command can be overridden by moderators on a guild-specific basis, disregarding this setting.
If
None
is returned, it means everyone can use the command by default. If an emptyPermissions
object is returned (that is, all permissions set toFalse
), this means no one can use the command.New in version 2.5.
- Type:
Optional[
Permissions
]
- property dm_permission[source]¶
Whether this command can be used in DMs with the bot.
New in version 2.5.
Deprecated since version 2.10: Use
contexts
instead. This is equivalent to theInteractionContextTypes.bot_dm
flag.
APIUserCommand¶
- class disnake.APIUserCommand[source]¶
A user context menu command returned by the API.
New in version 2.4.
- name_localizations¶
Localizations for
name
.New in version 2.5.
- Type:
- nsfw¶
Whether this command is age-restricted.
New in version 2.8.
- Type:
- install_types¶
The installation types where the command is available. Defaults to
ApplicationInstallTypes.guild
only. Only available for global commands.New in version 2.10.
- Type:
Optional[
ApplicationInstallTypes
]
- contexts¶
The interaction contexts where the command can be used. Only available for global commands.
New in version 2.10.
- Type:
Optional[
InteractionContextTypes
]
- guild_id¶
The ID of the guild this user command is enabled in, or
None
if it’s global.- Type:
Optional[
int
]
- property default_member_permissions[source]¶
The default required member permissions for this command. A member must have all these permissions to be able to invoke the command in a guild.
This is a default value, the set of users/roles that may invoke this command can be overridden by moderators on a guild-specific basis, disregarding this setting.
If
None
is returned, it means everyone can use the command by default. If an emptyPermissions
object is returned (that is, all permissions set toFalse
), this means no one can use the command.New in version 2.5.
- Type:
Optional[
Permissions
]
- property dm_permission[source]¶
Whether this command can be used in DMs with the bot.
New in version 2.5.
Deprecated since version 2.10: Use
contexts
instead. This is equivalent to theInteractionContextTypes.bot_dm
flag.
APIMessageCommand¶
- class disnake.APIMessageCommand[source]¶
A message context menu command returned by the API.
New in version 2.4.
- name_localizations¶
Localizations for
name
.New in version 2.5.
- Type:
- nsfw¶
Whether this command is age-restricted.
New in version 2.8.
- Type:
- install_types¶
The installation types where the command is available. Defaults to
ApplicationInstallTypes.guild
only. Only available for global commands.New in version 2.10.
- Type:
Optional[
ApplicationInstallTypes
]
- contexts¶
The interaction contexts where the command can be used. Only available for global commands.
New in version 2.10.
- Type:
Optional[
InteractionContextTypes
]
- guild_id¶
The ID of the guild this message command is enabled in, or
None
if it’s global.- Type:
Optional[
int
]
- property default_member_permissions[source]¶
The default required member permissions for this command. A member must have all these permissions to be able to invoke the command in a guild.
This is a default value, the set of users/roles that may invoke this command can be overridden by moderators on a guild-specific basis, disregarding this setting.
If
None
is returned, it means everyone can use the command by default. If an emptyPermissions
object is returned (that is, all permissions set toFalse
), this means no one can use the command.New in version 2.5.
- Type:
Optional[
Permissions
]
- property dm_permission[source]¶
Whether this command can be used in DMs with the bot.
New in version 2.5.
Deprecated since version 2.10: Use
contexts
instead. This is equivalent to theInteractionContextTypes.bot_dm
flag.
ApplicationCommandPermissions¶
- defis_all_channels
- defis_everyone
GuildApplicationCommandPermissions¶
- class disnake.GuildApplicationCommandPermissions[source]¶
Represents application command permissions in a guild.
Changed in version 2.5: Can now also represent application-wide permissions that apply to every command by default.
- id¶
The application command’s ID, or the application ID if these are application-wide permissions.
- Type:
- permissions¶
A list of
ApplicationCommandPermissions
.- Type:
Data Classes¶
ApplicationCommand¶
- class disnake.ApplicationCommand[source]¶
The base class for application commands.
The following classes implement this ABC:
- type¶
The command type
- Type:
- name_localizations¶
Localizations for
name
.New in version 2.5.
- Type:
- nsfw¶
Whether this command is age-restricted. Defaults to
False
.New in version 2.8.
- Type:
- install_types¶
The installation types where the command is available. Defaults to
ApplicationInstallTypes.guild
only. Only available for global commands.New in version 2.10.
- Type:
Optional[
ApplicationInstallTypes
]
- contexts¶
The interaction contexts where the command can be used. Only available for global commands.
New in version 2.10.
- Type:
Optional[
InteractionContextTypes
]
- property default_member_permissions[source]¶
The default required member permissions for this command. A member must have all these permissions to be able to invoke the command in a guild.
This is a default value, the set of users/roles that may invoke this command can be overridden by moderators on a guild-specific basis, disregarding this setting.
If
None
is returned, it means everyone can use the command by default. If an emptyPermissions
object is returned (that is, all permissions set toFalse
), this means no one can use the command.New in version 2.5.
- Type:
Optional[
Permissions
]
- property dm_permission[source]¶
Whether this command can be used in DMs with the bot.
New in version 2.5.
Deprecated since version 2.10: Use
contexts
instead. This is equivalent to theInteractionContextTypes.bot_dm
flag.
SlashCommand¶
- defadd_option
- class disnake.SlashCommand[source]¶
The base class for building slash commands.
- name_localizations¶
Localizations for
name
.New in version 2.5.
- Type:
- description_localizations¶
Localizations for
description
.New in version 2.5.
- Type:
- nsfw¶
Whether this command is age-restricted. Defaults to
False
.New in version 2.8.
- Type:
- install_types¶
The installation types where the command is available. Defaults to
ApplicationInstallTypes.guild
only. Only available for global commands.New in version 2.10.
- Type:
Optional[
ApplicationInstallTypes
]
- contexts¶
The interaction contexts where the command can be used. Only available for global commands.
New in version 2.10.
- Type:
Optional[
InteractionContextTypes
]
- add_option(name, description=None, type=None, required=False, choices=None, options=None, channel_types=None, autocomplete=False, min_value=None, max_value=None, min_length=None, max_length=None)[source]¶
Adds an option to the current list of options, parameters are the same as for
Option
- property default_member_permissions[source]¶
The default required member permissions for this command. A member must have all these permissions to be able to invoke the command in a guild.
This is a default value, the set of users/roles that may invoke this command can be overridden by moderators on a guild-specific basis, disregarding this setting.
If
None
is returned, it means everyone can use the command by default. If an emptyPermissions
object is returned (that is, all permissions set toFalse
), this means no one can use the command.New in version 2.5.
- Type:
Optional[
Permissions
]
- property dm_permission[source]¶
Whether this command can be used in DMs with the bot.
New in version 2.5.
Deprecated since version 2.10: Use
contexts
instead. This is equivalent to theInteractionContextTypes.bot_dm
flag.
UserCommand¶
- class disnake.UserCommand[source]¶
A user context menu command.
- name_localizations¶
Localizations for
name
.New in version 2.5.
- Type:
- nsfw¶
Whether this command is age-restricted. Defaults to
False
.New in version 2.8.
- Type:
- install_types¶
The installation types where the command is available. Defaults to
ApplicationInstallTypes.guild
only. Only available for global commands.New in version 2.10.
- Type:
Optional[
ApplicationInstallTypes
]
- contexts¶
The interaction contexts where the command can be used. Only available for global commands.
New in version 2.10.
- Type:
Optional[
InteractionContextTypes
]
- property default_member_permissions[source]¶
The default required member permissions for this command. A member must have all these permissions to be able to invoke the command in a guild.
This is a default value, the set of users/roles that may invoke this command can be overridden by moderators on a guild-specific basis, disregarding this setting.
If
None
is returned, it means everyone can use the command by default. If an emptyPermissions
object is returned (that is, all permissions set toFalse
), this means no one can use the command.New in version 2.5.
- Type:
Optional[
Permissions
]
- property dm_permission[source]¶
Whether this command can be used in DMs with the bot.
New in version 2.5.
Deprecated since version 2.10: Use
contexts
instead. This is equivalent to theInteractionContextTypes.bot_dm
flag.
MessageCommand¶
- class disnake.MessageCommand[source]¶
A message context menu command
- name_localizations¶
Localizations for
name
.New in version 2.5.
- Type:
- nsfw¶
Whether this command is age-restricted. Defaults to
False
.New in version 2.8.
- Type:
- install_types¶
The installation types where the command is available. Defaults to
ApplicationInstallTypes.guild
only. Only available for global commands.New in version 2.10.
- Type:
Optional[
ApplicationInstallTypes
]
- contexts¶
The interaction contexts where the command can be used. Only available for global commands.
New in version 2.10.
- Type:
Optional[
InteractionContextTypes
]
- property default_member_permissions[source]¶
The default required member permissions for this command. A member must have all these permissions to be able to invoke the command in a guild.
This is a default value, the set of users/roles that may invoke this command can be overridden by moderators on a guild-specific basis, disregarding this setting.
If
None
is returned, it means everyone can use the command by default. If an emptyPermissions
object is returned (that is, all permissions set toFalse
), this means no one can use the command.New in version 2.5.
- Type:
Optional[
Permissions
]
- property dm_permission[source]¶
Whether this command can be used in DMs with the bot.
New in version 2.5.
Deprecated since version 2.10: Use
contexts
instead. This is equivalent to theInteractionContextTypes.bot_dm
flag.
Option¶
- defadd_choice
- defadd_option
- class disnake.Option(name, description=None, type=None, required=False, choices=None, options=None, channel_types=None, autocomplete=False, min_value=None, max_value=None, min_length=None, max_length=None)[source]¶
Represents a slash command option.
- Parameters:
name (Union[
str
,Localized
]) –The option’s name.
Changed in version 2.5: Added support for localizations.
description (Optional[Union[
str
,Localized
]]) –The option’s description.
Changed in version 2.5: Added support for localizations.
type (
OptionType
) – The option type, e.g.OptionType.user
.required (
bool
) – Whether this option is required.choices (Union[Sequence[
OptionChoice
], Sequence[Union[str
,int
,float
]], Mapping[str
, Union[str
,int
,float
]]]) – The pre-defined choices for this option.options (List[
Option
]) – The list of sub options. Normally you don’t have to specify it directly, instead consider using@main_cmd.sub_command
or@main_cmd.sub_command_group
decorators.channel_types (List[
ChannelType
]) – The list of channel types that your option supports, if the type isOptionType.channel
. By default, it supports all channel types.autocomplete (
bool
) – Whether this option can be autocompleted.min_value (Union[
int
,float
]) – The minimum value permitted.max_value (Union[
int
,float
]) – The maximum value permitted.min_length (
int
) –The minimum length for this option if this is a string option.
New in version 2.6.
max_length (
int
) –The maximum length for this option if this is a string option.
New in version 2.6.
- type¶
The option type, e.g.
OptionType.user
.- Type:
- choices¶
The list of pre-defined choices.
- Type:
List[
OptionChoice
]
- options¶
The list of sub options. Normally you don’t have to specify it directly, instead consider using
@main_cmd.sub_command
or@main_cmd.sub_command_group
decorators.- Type:
List[
Option
]
- channel_types¶
The list of channel types that your option supports, if the type is
OptionType.channel
. By default, it supports all channel types.- Type:
List[
ChannelType
]
- min_length¶
The minimum length for this option if this is a string option.
New in version 2.6.
- Type:
- max_length¶
The maximum length for this option if this is a string option.
New in version 2.6.
- Type:
- add_choice(name, value)[source]¶
Adds an OptionChoice to the list of current choices, parameters are the same as for
OptionChoice
.
OptionChoice¶
ApplicationInstallTypes¶
- class disnake.ApplicationInstallTypes[source]¶
Represents the location(s) in which an application or application command can be installed.
See the official documentation for more info.
- x == y
Checks if two ApplicationInstallTypes instances are equal.
- x != y
Checks if two ApplicationInstallTypes instances are not equal.
- x <= y
Checks if an ApplicationInstallTypes instance is a subset of another ApplicationInstallTypes instance.
- x >= y
Checks if an ApplicationInstallTypes instance is a superset of another ApplicationInstallTypes instance.
- x < y
Checks if an ApplicationInstallTypes instance is a strict subset of another ApplicationInstallTypes instance.
- x > y
Checks if an ApplicationInstallTypes instance is a strict superset of another ApplicationInstallTypes instance.
- x | y, x |= y
Returns a new ApplicationInstallTypes instance with all enabled flags from both x and y. (Using
|=
will update in place).
- x & y, x &= y
Returns a new ApplicationInstallTypes instance with only flags enabled on both x and y. (Using
&=
will update in place).
- x ^ y, x ^= y
Returns a new ApplicationInstallTypes instance with only flags enabled on one of x or y, but not both. (Using
^=
will update in place).
- ~x
Returns a new ApplicationInstallTypes instance with all flags from x inverted.
- hash(x)
Returns the flag’s hash.
- iter(x)
Returns an iterator of
(name, value)
pairs. This allows it to be, for example, constructed as a dict or a list of pairs. Note that aliases are not shown.
Additionally supported are a few operations on class attributes.
- ApplicationInstallTypes.y | ApplicationInstallTypes.z, ApplicationInstallTypes(y=True) | ApplicationInstallTypes.z
Returns an ApplicationInstallTypes instance with all provided flags enabled.
- ~ApplicationInstallTypes.y
Returns an ApplicationInstallTypes instance with all flags except
y
inverted from their default value.
New in version 2.10.
- value¶
The raw value. You should query flags via the properties rather than using this raw value.
- Type:
- classmethod all()[source]¶
A factory method that creates an
ApplicationInstallTypes
instance with everything enabled.
InteractionContextTypes¶
- class disnake.InteractionContextTypes[source]¶
Represents the context(s) in which an application command can be used.
See the official documentation for more info.
- x == y
Checks if two InteractionContextTypes instances are equal.
- x != y
Checks if two InteractionContextTypes instances are not equal.
- x <= y
Checks if an InteractionContextTypes instance is a subset of another InteractionContextTypes instance.
- x >= y
Checks if an InteractionContextTypes instance is a superset of another InteractionContextTypes instance.
- x < y
Checks if an InteractionContextTypes instance is a strict subset of another InteractionContextTypes instance.
- x > y
Checks if an InteractionContextTypes instance is a strict superset of another InteractionContextTypes instance.
- x | y, x |= y
Returns a new InteractionContextTypes instance with all enabled flags from both x and y. (Using
|=
will update in place).
- x & y, x &= y
Returns a new InteractionContextTypes instance with only flags enabled on both x and y. (Using
&=
will update in place).
- x ^ y, x ^= y
Returns a new InteractionContextTypes instance with only flags enabled on one of x or y, but not both. (Using
^=
will update in place).
- ~x
Returns a new InteractionContextTypes instance with all flags from x inverted.
- hash(x)
Returns the flag’s hash.
- iter(x)
Returns an iterator of
(name, value)
pairs. This allows it to be, for example, constructed as a dict or a list of pairs. Note that aliases are not shown.
Additionally supported are a few operations on class attributes.
- InteractionContextTypes.y | InteractionContextTypes.z, InteractionContextTypes(y=True) | InteractionContextTypes.z
Returns an InteractionContextTypes instance with all provided flags enabled.
- ~InteractionContextTypes.y
Returns an InteractionContextTypes instance with all flags except
y
inverted from their default value.
New in version 2.10.
- value¶
The raw value. You should query flags via the properties rather than using this raw value.
- Type:
- classmethod all()[source]¶
A factory method that creates an
InteractionContextTypes
instance with everything enabled.
Enumerations¶
OptionType¶
- class disnake.OptionType[source]¶
Represents the type of an option.
New in version 2.1.
- sub_command¶
Represents a sub command of the main command or group.
- sub_command_group¶
Represents a sub command group of the main command.
- string¶
Represents a string option.
- integer¶
Represents an integer option.
- boolean¶
Represents a boolean option.
- user¶
Represents a user option.
- channel¶
Represents a channel option.
- role¶
Represents a role option.
- mentionable¶
Represents a role + user option.
- number¶
Represents a float option.
- attachment¶
Represents an attachment option.
New in version 2.4.