Application Commands

This section documents everything related to Discord’s application commands.

Discord Models

APISlashCommand

class disnake.APISlashCommand[source]

A slash command returned by the API.

New in version 2.4.

name

The slash command’s name.

Type:

str

name_localizations

Localizations for name.

New in version 2.5.

Type:

LocalizationValue

description

The slash command’s description.

Type:

str

description_localizations

Localizations for description.

New in version 2.5.

Type:

LocalizationValue

dm_permission

Whether this command can be used in DMs.

New in version 2.5.

Type:

bool

nsfw

Whether this command is age-restricted.

New in version 2.8.

Type:

bool

id

The slash command’s ID.

Type:

int

options

The list of options the slash command has.

Type:

List[Option]

application_id

The application ID this command belongs to.

Type:

int

guild_id

The ID of the guild this slash command is enabled in, or None if it’s global.

Type:

Optional[int]

version

Autoincrementing version identifier updated during substantial record changes.

Type:

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 empty Permissions object is returned (that is, all permissions set to False), this means no one can use the command.

New in version 2.5.

Type:

Optional[Permissions]

APIUserCommand

class disnake.APIUserCommand[source]

A user context menu command returned by the API.

New in version 2.4.

name

The user command’s name.

Type:

str

name_localizations

Localizations for name.

New in version 2.5.

Type:

LocalizationValue

dm_permission

Whether this command can be used in DMs.

New in version 2.5.

Type:

bool

nsfw

Whether this command is age-restricted.

New in version 2.8.

Type:

bool

id

The user command’s ID.

Type:

int

application_id

The application ID this command belongs to.

Type:

int

guild_id

The ID of the guild this user command is enabled in, or None if it’s global.

Type:

Optional[int]

version

Autoincrementing version identifier updated during substantial record changes.

Type:

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 empty Permissions object is returned (that is, all permissions set to False), this means no one can use the command.

New in version 2.5.

Type:

Optional[Permissions]

APIMessageCommand

class disnake.APIMessageCommand[source]

A message context menu command returned by the API.

New in version 2.4.

name

The message command’s name.

Type:

str

name_localizations

Localizations for name.

New in version 2.5.

Type:

LocalizationValue

dm_permission

Whether this command can be used in DMs.

New in version 2.5.

Type:

bool

nsfw

Whether this command is age-restricted.

New in version 2.8.

Type:

bool

id

The message command’s ID.

Type:

int

application_id

The application ID this command belongs to.

Type:

int

guild_id

The ID of the guild this message command is enabled in, or None if it’s global.

Type:

Optional[int]

version

Autoincrementing version identifier updated during substantial record changes.

Type:

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 empty Permissions object is returned (that is, all permissions set to False), this means no one can use the command.

New in version 2.5.

Type:

Optional[Permissions]

ApplicationCommandPermissions

Attributes
class disnake.ApplicationCommandPermissions[source]

Represents application command permissions for a role, user, or channel.

id

The ID of the role, user, or channel.

Type:

int

type

The type of the target.

Type:

ApplicationCommandPermissionType

permission

Whether to allow or deny the access to the application command.

Type:

bool

is_everyone()[source]

Whether this permission object is affecting the @everyone role.

New in version 2.5.

Return type:

bool

is_all_channels()[source]

Whether this permission object is affecting all channels.

New in version 2.5.

Return type:

bool

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:

int

application_id

The application ID this command belongs to.

Type:

int

guild_id

The ID of the guild where these permissions are applied.

Type:

int

permissions

A list of ApplicationCommandPermissions.

Type:

List[ApplicationCommandPermissions]

Data Classes

ApplicationCommand

class disnake.ApplicationCommand[source]

The base class for application commands.

The following classes implement this ABC:

type

The command type

Type:

ApplicationCommandType

name

The command name

Type:

str

name_localizations

Localizations for name.

New in version 2.5.

Type:

LocalizationValue

dm_permission

Whether this command can be used in DMs. Defaults to True.

New in version 2.5.

Type:

bool

nsfw

Whether this command is age-restricted. Defaults to False.

New in version 2.8.

Type:

bool

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 empty Permissions object is returned (that is, all permissions set to False), this means no one can use the command.

New in version 2.5.

Type:

Optional[Permissions]

SlashCommand

class disnake.SlashCommand[source]

The base class for building slash commands.

name

The slash command’s name.

Type:

str

name_localizations

Localizations for name.

New in version 2.5.

Type:

LocalizationValue

description

The slash command’s description.

Type:

str

description_localizations

Localizations for description.

New in version 2.5.

Type:

LocalizationValue

dm_permission

Whether this command can be used in DMs. Defaults to True.

New in version 2.5.

Type:

bool

nsfw

Whether this command is age-restricted. Defaults to False.

New in version 2.8.

Type:

bool

options

The list of options the slash command has.

Type:

List[Option]

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 empty Permissions object is returned (that is, all permissions set to False), this means no one can use the command.

New in version 2.5.

Type:

Optional[Permissions]

UserCommand

class disnake.UserCommand[source]

A user context menu command.

name

The user command’s name.

Type:

str

name_localizations

Localizations for name.

New in version 2.5.

Type:

LocalizationValue

dm_permission

Whether this command can be used in DMs. Defaults to True.

New in version 2.5.

Type:

bool

nsfw

Whether this command is age-restricted. Defaults to False.

New in version 2.8.

Type:

bool

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 empty Permissions object is returned (that is, all permissions set to False), this means no one can use the command.

New in version 2.5.

Type:

Optional[Permissions]

MessageCommand

class disnake.MessageCommand[source]

A message context menu command

name

The message command’s name.

Type:

str

name_localizations

Localizations for name.

New in version 2.5.

Type:

LocalizationValue

dm_permission

Whether this command can be used in DMs. Defaults to True.

New in version 2.5.

Type:

bool

nsfw

Whether this command is age-restricted. Defaults to False.

New in version 2.8.

Type:

bool

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 empty Permissions object is returned (that is, all permissions set to False), this means no one can use the command.

New in version 2.5.

Type:

Optional[Permissions]

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 is OptionType.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.

name

The option’s name.

Type:

str

description

The option’s description.

Type:

str

type

The option type, e.g. OptionType.user.

Type:

OptionType

required

Whether this option is required.

Type:

bool

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]

autocomplete

Whether this option can be autocompleted.

Type:

bool

min_value

The minimum value permitted.

Type:

Union[int, float]

max_value

The maximum value permitted.

Type:

Union[int, float]

min_length

The minimum length for this option if this is a string option.

New in version 2.6.

Type:

int

max_length

The maximum length for this option if this is a string option.

New in version 2.6.

Type:

int

add_choice(name, value)[source]

Adds an OptionChoice to the list of current choices, parameters are the same as for OptionChoice.

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.

OptionChoice

class disnake.OptionChoice[source]

Represents an option choice.

Parameters:
  • name (Union[str, Localized]) –

    The name of the option choice (visible to users).

    Changed in version 2.5: Added support for localizations.

  • value (Union[str, int]) – The value of the option choice.

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.

ApplicationCommandType

class disnake.ApplicationCommandType[source]

Represents the type of an application command.

New in version 2.1.

chat_input

Represents a slash command.

user

Represents a user command from the context menu.

message

Represents a message command from the context menu.

ApplicationCommandPermissionType

class disnake.ApplicationCommandPermissionType[source]

Represents the type of a permission of an application command.

New in version 2.5.

role

Represents a permission that affects roles.

user

Represents a permission that affects users.

channel

Represents a permission that affects channels.

Events