ApplicationCommand

Methods
class discord.ApplicationCommand

Bases: object

The base class for application commands

@error(coro)

A decorator to set an error handler for this command similar to on_application_command_error() but only for this command

Parameters:

coro (Callable[[ApplicationCommandInteraction, Exception], Coroutine]) – The coroutine to use as an error handler.

Raises:

TypeError – If the error handler is not a coroutine.

property cog

The cog associated with this command if any.

Type:

Optional[Cog]

property id

The id of the command, only set if the bot is running

Type:

Optional[int]

property created_at

The creation time of the command in UTC, only set if the bot is running

Type:

Optional[datetime]

property type

The type of the command

Type:

ApplicationCommandType

property guild_id

Th id this command belongs to, if any

Type:

Optional[int]

await delete()

This function is a coroutine.

Deletes the application command

SlashCommand

class discord.SlashCommand

Bases: ApplicationCommand

Represents a slash-command.

Note

You should use discord.Client.slash_command() or in cogs slash_command() decorator by default to create this.

Parameters:
  • name (str) – The name of the slash-command. Must be between 1 and 32 characters long and oly contain a-z, _ and -.

  • description (str) – The description of the command shows up in discord. Between 1 and 100 characters long.

  • default_member_permissions (Optional[Union[Permissions, int]]) – Permissions that a Member needs by default to execute(see) the command.

  • allow_dm (Optional[bool]) – Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible.

  • is_nsfw (bool) –

    Whether this command is an NSFW command, default False

    Note

    Currently all sub-commands of a command that is marked as NSFW are NSFW too.

  • options (Optional[List[SlashCommandOption]]) – A list of max. 25 options for the command. Required options must be listed before optional ones.

  • connector (Optional[Dict[str, str]]) – A dictionary containing the name of function-parameters as keys and the name of the option as values. Useful for using non-ascii Letters in your option names without getting ide-errors.

  • **kwargs – Keyword arguments used for internal handling.

@autocomplete_callback(coro)

A decorator that sets a coroutine function as the function that will be called when discord sends an autocomplete interaction for this command.

Parameters:

coro (Callable[[AutocompleteInteraction, …], Coroutine]) – The function that should be set as SlashCommand.autocomplete_func for this command. Must take the same amount of params the command itself takes.

Raises:

TypeError – The function passed is not a coroutine.

property mention

Returns a string the client renders as a mention of the command

Note

This requires that the bot is running and the command is cached

Return type:

The mention of the command

Raises:

TypeError – The bot is not running and so the id’s not cached

property cog

The cog the slash command belongs to

Type:

Optional[ext.commands.Cog]

property has_subcommands

Whether the command has sub-commands or not

Type:

bool

property sub_commands

A list of sub-commands or sub-command groups the command has.

Type:

List[Union[SubCommand, SubCommandGroup]

property options

A list of SlashCommandOption the command has.

property created_at

The creation time of the command in UTC, only set if the bot is running

Type:

Optional[datetime]

await delete()

This function is a coroutine.

Deletes the application command

error(coro)

A decorator to set an error handler for this command similar to on_application_command_error() but only for this command

Parameters:

coro (Callable[[ApplicationCommandInteraction, Exception], Coroutine]) – The coroutine to use as an error handler.

Raises:

TypeError – If the error handler is not a coroutine.

property guild_id

Th id this command belongs to, if any

Type:

Optional[int]

property id

The id of the command, only set if the bot is running

Type:

Optional[int]

property type

The type of the command

Type:

ApplicationCommandType

class discord.SubCommand

Bases: SlashCommandOption

@autocomplete_callback(coro)
A decorator that sets a coroutine function as the function that will be called

when discord sends an autocomplete interaction for this sub-command.

coro: Callable[[AutocompleteInteraction, …], Coroutine]

The function that should be set as autocomplete_func for this command. Must take the same amount of params the sub-command itself takes.

TypeError

The function passed is not a coroutine.

@error(coro)

A decorator to set an error handler for this command similar to on_application_command_error() but only for this command

Parameters:

coro (Callable[[ApplicationCommandInteraction, Exception], Coroutine]) – The coroutine to use as an error handler.

Raises:

TypeError – If the error handler is not a coroutine.

property base_command

Returns the base command of the sub-command

For example if the command is /a b c or /a c the base command would be a

Returns:

The base command of the sub-command

Return type:

SlashCommand

property is_nsfw

Whether this command is nsfw

Note

Currently, any sub command of a base-command that is nsfw will be nsfw too.

Returns:

Whether this command is nsfw or not

Return type:

bool

property mention

Returns a string the client renders as a mention of the command

Note

This requires that the bot is running and the command is cached

Return type:

The mention of the command

Raises:

TypeError – The bot is not running and so the id’s not cached

property qualified_name

Returns a string representing the full name of the command

For example if the command is /a b c or /a c the qualified name would be a b c or a c

Returns:

The full name of the command

Return type:

str

SlashCommandOption

class discord.SlashCommandOption

Bases: object

Representing an option for a SlashCommand/SubCommand.

Parameters:
  • option_type (Union[OptionType, int, type]) –

    Could be any of OptionType’s attributes, an integer between 0 and 10 or a type like discord.Member, discord.TextChannel or str.

    Note

    If the option_type is a type, that subclasses GuildChannel the type of the channel would set as the default channel_types.

  • name (str) – The 1-32 characters long name of the option shows up in discord. The name must be the same as the one of the parameter for the slash-command or connected using connector of SlashCommand/SubCommand or the method that generates one of these.

  • description (str) – The 1-100 characters long description of the option shows up in discord.

  • required (Optional[bool]) – Weather this option must be provided by the user, default True. If False, the parameter of the slash-command that takes this option needs a default value.

  • choices (Optional[List[Union[SlashCommandOptionChoice, str, int, float]]]) –

    A list of up to 25 choices the user could select. Only valid if the option_type is one of string, integer or number.

    Note

    If you want to have values that are not the same as their name, you can use SlashCommandOptionChoice

    The value’s of the choices must be of the option_type of this option (e.g. str, int or float). If choices are set they are the only options a user could pass.

  • autocomplete (Optional[bool]) –

    Whether to enable autocomplete interactions for this option, default False. With autocomplete, you can check the user’s input and send matching choices to the client.

    Note

    Autocomplete can only be used with options of the type string, integer or number. If autocomplete is activated, the option cannot have choices .

  • min_value (Optional[Union[int, float]]) – If the option_type is one of integer or number this is the minimum value the users input must be of.

  • max_value (Optional[Union[int, float]]) – If the option_type is one of integer or number this is the maximum value the users input could be of.

  • min_length (Optional[int]) – If the option_type is string, this is the minimum length (minimum of 0, maximum of 6000)

  • max_length (Optional[int]) – If the option_type is string, this is the maximum length (minimum of 1, maximum of 6000)

  • channel_types (Optional[List[Union[abc.GuildChannel, ChannelType, int]]]) – A list of ChannelType or the type itself like TextChannel or StageChannel the user could select. Only valid if option_type is channel.

  • default (Optional[Any]) – The default value that should be passed to the function if the option is not provided, default None. Usually used for autocomplete callback.

  • converter (Optional[Union[discord.ext.commands.Greedy, discord.ext.commands.Converter]]) – A subclass of Converter to use for converting the value. Only valid for option_type string or integer

  • ignore_conversion_failures (Optional[bool]) – Whether conversion failures should be ignored and the value should be passed without conversion instead. Default False

property autocomplete

Whether to enable autocomplete interactions for this option. With autocomplete, you can check the user’s input and send matching choices to the client.

Note

Autocomplete can only be used with options of the type string, integer or number. If autocomplete is activated, the option cannot have choices.

property choices

The choices that are set for this option

Return type:

Optional[List[SlashCommandOptionChoice]]

property min_value

The minimum value a user could enter that is set

Return type:

Optional[Union[int, float]]

property max_value

The maximum value a user could enter that is set.

Return type:

Optional[Union[int, float]]

property channel_types

The types of channels that could be selected.

Return type:

Optional[List[ChannelType]]

SlashCommandOptionChoice

class discord.SlashCommandOptionChoice

Bases: object

A class representing a choice for a SlashCommandOption or to use in AutocompleteInteraction.send_choices()

Parameters:
  • name (Union[str, int, float]) – The 1-100 characters long name that will show in the client.

  • value (Union[str, int, float, None]) –

    The value that will send as the options value. Must be of the type the SlashCommandOption is of (str, int or float).

    Note

    If this is left empty it takes the name as value.

  • name_localizations (Optional[Localizations]) – Localized names for the choice.

UserCommand

Methods
class discord.UserCommand

Bases: ApplicationCommand

Represents a user context-menu command

Note

You should use discord.Client.user_command() or in cogs user_command() decorator by default to create this.

Parameters:
  • name (Optional[str]) – The name of the user-command, default to the functions name. Must be between 1-32 characters long.

  • default_required_permissions (Optional[Permissions]) – Permissions that a Member needs by default to execute(see) the command.

  • allow_dm (bool) – Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible.

property cog

The cog associated with this command if any.

Type:

Optional[Cog]

property created_at

The creation time of the command in UTC, only set if the bot is running

Type:

Optional[datetime]

await delete()

This function is a coroutine.

Deletes the application command

error(coro)

A decorator to set an error handler for this command similar to on_application_command_error() but only for this command

Parameters:

coro (Callable[[ApplicationCommandInteraction, Exception], Coroutine]) – The coroutine to use as an error handler.

Raises:

TypeError – If the error handler is not a coroutine.

property guild_id

Th id this command belongs to, if any

Type:

Optional[int]

property id

The id of the command, only set if the bot is running

Type:

Optional[int]

property type

The type of the command

Type:

ApplicationCommandType

MessageCommand

Methods
class discord.MessageCommand

Bases: ApplicationCommand

Represents a message context-menu command

Note

You should use discord.Client.message_command() or in cogs message_command() decorator by default to create this.

Parameters:
  • name (Optional[str]) – The name of the message-command, default to the functions name. Must be between 1-32 characters long.

  • default_required_permissions (Optional[Permissions]) – Permissions that a Member needs by default to execute(see) the command.

  • allow_dm (Optional[Permissions]) – Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible.

property cog

The cog associated with this command if any.

Type:

Optional[Cog]

property created_at

The creation time of the command in UTC, only set if the bot is running

Type:

Optional[datetime]

await delete()

This function is a coroutine.

Deletes the application command

error(coro)

A decorator to set an error handler for this command similar to on_application_command_error() but only for this command

Parameters:

coro (Callable[[ApplicationCommandInteraction, Exception], Coroutine]) – The coroutine to use as an error handler.

Raises:

TypeError – If the error handler is not a coroutine.

property guild_id

Th id this command belongs to, if any

Type:

Optional[int]

property id

The id of the command, only set if the bot is running

Type:

Optional[int]

property type

The type of the command

Type:

ApplicationCommandType

GuildAppCommandPermissions

class discord.GuildAppCommandPermissions

Bases: object

Represents a list of permissions for an application command in a guild.

command_id

The ID of the application command.

Type:

int

application_id

The ID of the application.

Type:

int

guild_id

The ID of the guild.

Type:

int

permissions

The permissions for the guild’s application commands.

Type:

List[AppCommandPermission]

AppCommandPermissions

class discord.AppCommandPermission

Bases: object

Represents a permission for an application command.

id

The ID of the role, user, or channel.

Note

This can be the guild ID for the default role (@everyone) or guild ID - 1 for all channels.

Type:

Union[str, int]

type

The target this permission applies to.

Type:

AppCommandPermissionType

permission

True to allow, False to disallow.

Type:

bool

Represents a permission for an application command.

Parameters:
  • id (Union[str, int]) –

    The ID of the role, user, or channel.

    Note

    This can be the guild ID for the default role (@everyone) or guild ID - 1 for all channels.

  • type (AppCommandPermissionType) – The target this permission applies to.

  • permission (bool) – True to allow, False to disallow.

classmethod await all_channels(guild_id, permission)

Creates a new AppCommandPermission for all channels in a guild.

This is equivalent to:

AppCommandPermission(guild_id - 1, AppCommandPermissionType.ROLE, permission)
Parameters:
  • guild_id (Union[str, int]) – The guild ID.

  • permission (bool) – The permission.

Returns:

The new AppCommandPermission.

Return type:

AppCommandPermission

Miscellaneous

class discord.Mentionable

Bases: object

This class can be used as an annotation for a slash-command option to allow both Member and Role