Application Command Models#

class interactions.client.models.command.Choice(kwargs_dict=None, /, **other_kwargs)[source]#

A class object representing the choice of an option.

Note

value allows float as a passable value type, whereas it’s supposed to be double.

The structure for a choice:

interactions.Choice(name="Choose me! :(", value="choice_one")
Variables:
  • name (str) – The name of the choice.

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

  • name_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the name field. This enforces the same restrictions as the name field.

class interactions.client.models.command.Option(kwargs_dict=None, /, **other_kwargs)[source]#

A class object representing the option of an application command.

Note

options is only present for when a subcommand has been established.

min_values and max_values are useful primarily for integer based options.

The structure for an option:

interactions.Option(
    type=interactions.OptionType.STRING,
    name="option_name",
    description="i'm a meaningless option in your life. (depressed noises)",
    required=True,
    choices=[interactions.Choice(...)], # optional
)
Variables:
  • type (OptionType) – The type of option.

  • name (str) – The name of the option.

  • description (str) – The description of the option.

  • focused (bool) – Whether the option is currently being autocompleted or not.

  • required (Optional[bool]) – Whether the option has to be filled out.

  • value (Optional[str]) – The value that’s currently typed out, if autocompleting.

  • choices (Optional[List[Choice]]) – The list of choices to select from.

  • options (Optional[List[Option]]) – The list of subcommand options included.

  • channel_types (Optional[List[ChannelType]]) – Restrictive shown channel types, if given.

  • min_value (Optional[int]) – The minimum value supported by the option.

  • max_value (Optional[int]) – The maximum value supported by the option.

  • min_length (Optional[int]) – The minimum length supported by the option.

  • max_length (Optional[int]) – The maximum length supported by the option.

  • autocomplete (Optional[bool]) – A status denoting whether this option is an autocomplete option.

  • name_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the name field. This enforces the same restrictions as the name field.

  • description_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the description field. This enforces the same restrictions as the description field.

  • converter (Optional[str]) – How the option value is passed to the function, if different than name

class interactions.client.models.command.ApplicationCommand(kwargs_dict=None, /, **other_kwargs)[source]#

A class object representing all types of commands.

Warning

This object is inferred upon whenever the client is caching information about commands from an HTTP request and/or the Gateway. Do not use this object for declaring commands.

Variables:
  • id (Snowflake) – The ID of the application command.

  • type (ApplicationCommandType) – The application command type.

  • application_id (Optional[Snowflake]) – The general application ID of the command itself.

  • guild_id (Optional[Snowflake]) – The guild ID of the application command.

  • name (str) – The name of the application command.

  • description (str) – The description of the application command.

  • options (Optional[List[Option]]) – The “options”/arguments of the application command.

  • default_permission (Optional[bool]) – The default permission accessibility state of the application command.

  • version (int) – The Application Command version autoincrement identifier.

  • default_member_permissions (str) – The default member permission state of the application command.

  • dm_permission (boolean) – The application permissions if executed in a Direct Message.

  • name_localizations (Optional[Dict[Union[str, Locale], str]]) – The localisation dictionary for the application command name, if any.

  • description_localizations (Optional[Dict[Union[str, Locale], str]]) – The localisation dictionary for the application command description, if any.

interactions.client.models.command.option(description='No description set', /, **kwargs)[source]#

New in version 4.3.0.

A decorator for adding options to a command.

The type and name of the option are defaulted to the parameter’s typehint and name.

When the name of the option differs from the parameter name, the converter field will default to the name of the parameter.

The structure of an option:

@client.command()
@interactions.option("description (optional)")  # kwargs are optional, same as Option
async def my_command(ctx, opt: str):
    ...
Parameters:
  • description (str) – The description of the option. Defaults to No description set.

  • **kwargs (dict) – The keyword arguments of the option, same as Option.

Return type:

Callable[[Callable[[…], Awaitable]], Callable[[…], Awaitable]]

class interactions.client.models.command.StopCommand[source]#

New in version 4.3.0.

A class that when returned from a command, the command chain is stopped.

Usage:

@bot.command()
async def foo(ctx):
    ... # do something
    return StopCommand  # does not execute `bar`
    # or `return StopCommand()`

@foo.subcommand()
async def bar(ctx):
    ...  # `bar` is not executed

This allows for custom checks that allow stopping the command chain.

class interactions.client.models.command.BaseResult(kwargs_dict=None, /, **other_kwargs)[source]#

New in version 4.3.0.

A class object representing the result of the base command.

Usage:

@bot.command()
async def foo(ctx):
    ... # do something
    return "done"  # return something

@foo.subcommand()
async def bar(ctx, base_res: BaseResult):
    print(base_res.result)  # "done"

Note

If the subcommand coroutine does not have enough parameters, the BaseResult will not be passed.

Variables:

result (Any) – The result of the base command.

class interactions.client.models.command.GroupResult(kwargs_dict=None, /, **other_kwargs)[source]#

New in version 4.3.0.

A class object representing the result of the base command.

Usage:

@bot.command()
async def foo(ctx):
    ... # do something
    return "done base"  # return something

@foo.group()
async def bar(ctx, base_res: BaseResult):
    print(base_res.result)  # "done base"
    return "done group"  # return something

@bar.subcommand()
async def pseudo(ctx, group_res: GroupResult):
    print(group_res.result)  # "done group"
    print(group_res.parent)  # BaseResult(result='done base')

Note

If the subcommand does not have enough arguments, the GroupResult will not be passed.

Variables:
  • result (Any) – The result of the base command.

  • parent (BaseResult) – The parent BaseResult.

class interactions.client.models.command.Command(kwargs_dict=None, /, **other_kwargs)[source]#

New in version 4.3.0.

A class object representing a command.

Warning

This object is meant to be used internally when creating new commands using the command decorators. Do not use this object for declaring commands.

Variables:
  • coro (Callable[..., Awaitable]) – The base command coroutine.

  • type (ApplicationCommandType) – The type of the command.

  • name (Optional[str]) – The name of the command. Defaults to the coroutine name.

  • description (Optional[str]) – The description of the command. Defaults to the docstring of the coroutine or "No description set".

  • options (Optional[List[Option]]) – The list of options for the base command.

  • scope (Optional[Union[int, Guild, List[int], List[Guild]]]) – The scope of the command.

  • default_member_permissions (Optional[str]) – The default member permissions of the command.

  • dm_permission (Optional[bool]) – The DM permission of the command.

  • name_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the name field. This enforces the same restrictions as the name field.

  • description_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the description field. This enforces the same restrictions as the description field.

  • default_scope (bool) – Whether the command should use the default scope. Defaults to True.

  • coroutines (Dict[str, Callable[..., Awaitable]]) – The dictionary of coroutines for the command.

  • num_options (Dict[str, int]) – The dictionary of the number of options per subcommand.

  • autocompletions (Dict[str, Union[Callable[..., Awaitable], str]]) – The dictionary of autocompletions for the command.

  • recent_group (Optional[str]) – The name of the group most recently utilized.

  • extension (Optional[Extension]) – The extension that the command belongs to, if any.

  • client (Client) – The client that the command belongs to.

  • listener (Optional[Listener]) – The listener, used for dispatching command errors.

property converters: dict#

Returns a dictionary with all converters added to the options of the command

property full_data: Union[dict, List[dict]]#

Returns the command data in JSON format.

Returns:

The command data in JSON format.

Return type:

Union[dict, List[dict]]

property has_subcommands: bool#

Checks if the command has subcommand options.

Returns:

Whether the command has subcommand options.

Return type:

bool

subcommand(group=<interactions.MISSING>, *, name=<interactions.MISSING>, description=<interactions.MISSING>, options=<interactions.MISSING>, name_localizations=<interactions.MISSING>, description_localizations=<interactions.MISSING>)[source]#

Decorator for creating a subcommand of the command.

The structure for a subcommand:

@bot.command()
async def base_command(ctx):
    pass  # do whatever you want here

@base_command.subcommand()
async def subcommand(ctx):
    pass  # do whatever you want here
    # you can also have a parameter for the base result

@base_command.subcommand("group_name")
async def subcommand_group(ctx):
    pass  # you can decide to create a subcommand group
          # without creating a group, like this

Note

If you want to create both subcommands and subcommands with groups, first create the subcommands without groups, then create the subcommands with groups.

Parameters:
  • group (Optional[str]) – The name of the group the subcommand belongs to. Defaults to the most recently used group.

  • name (Optional[str]) – The name of the subcommand. Defaults to the name of the coroutine.

  • description (Optional[str]) – The description of the subcommand. Defaults to the docstring of the coroutine.

  • options (Optional[List[Option]]) – The options of the subcommand.

  • name_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the name field. This enforces the same restrictions as the name field.

  • description_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the description field. This enforces the same restrictions as the description field.

Returns:

The Command object.

Return type:

Command

group(*, name=<interactions.MISSING>, description=<interactions.MISSING>, name_localizations=<interactions.MISSING>, description_localizations=<interactions.MISSING>)[source]#

Decorator for creating a group of the command.

The structure for a group:

@bot.command()
async def base_command(ctx):
    pass

@base_command.group()
async def group(ctx):
    """description"""
    pass  # you can also have a parameter for the base result

@group.subcommand()
async def subcommand_group(ctx):
    pass

Note

If you want to create both subcommands and subcommands with groups, first create the subcommands without groups, then create the subcommands with groups.

Parameters:
  • name (Optional[str]) – The name of the group. Defaults to the name of the coroutine.

  • description (Optional[str]) – The description of the group. Defaults to the docstring of the coroutine.

  • name_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the name field. This enforces the same restrictions as the name field.

  • description_localizations (Optional[Dict[Union[str, Locale], str]]) – The dictionary of localization for the description field. This enforces the same restrictions as the description field.

Returns:

The Command object.

Return type:

Command

property dispatcher: Callable[[...], Awaitable]#

Returns a coroutine that calls the command along with the subcommands, if any.

Note

The coroutine returned is never the same object.

Returns:

A coroutine that calls the command along with the subcommands, if any.

Return type:

Callable[…, Awaitable]

autocomplete(name=<interactions.MISSING>)[source]#

Decorator for creating an autocomplete for the command.

Parameters:

name (Optional[str]) – The name of the option to autocomplete. Defaults to the name of the coroutine.

Returns:

The coroutine

Return type:

Callable[…, Coroutine]

error(coro, /)[source]#

Decorator for assigning a callback coroutine to be called when an error occurs.

The structure of the decorator:

@bot.command()
async def command(ctx):
    raise Exception("Error")  # example error

@command.error
async def command_error(ctx, error):
    ...  # do something with the error

Note

The context and error are required as parameters, but you can also have additional parameters so that the base or group result (if any) and/or options are passed.

Parameters:

coro (Callable[..., Coroutine]) – The coroutine to be called when an error occurs.

Return type:

Callable[[…], Coroutine]