Skip to content

tanjun.commands#

Standard implementations of Tanjun's command objects.

tanjun.commands.menu #

Menu command implementations.

MenuCommand #

Bases: base.PartialCommand[tanjun.MenuContext], tanjun.MenuCommand[_MenuCommandCallbackSigT, _MenuTypeT]

Base class used for the standard menu command implementations.

__init__(callback, type_, name, /, *, always_defer=False, default_member_permissions=None, default_to_ephemeral=None, dm_enabled=None, is_global=True, _wrapped_command=None) #

Initialise a user or message menu command.

Note

Under the standard implementation, is_global is used to determine whether the command should be bulk set by [tanjun.Client.declare_global_commands][] or when declare_global_commands is True

Note

If you want your first response to be ephemeral while using always_defer, you must set default_to_ephemeral to True.

PARAMETER DESCRIPTION
callback

Callback to execute when the command is invoked.

This should be an asynchronous callback which takes one positional argument of type tanjun.abc.MenuContext, returns None and may use dependency injection to access other services.

TYPE: collections.abc.Callable[[tanjun.abc.MenuContext, ...], collections.abc.Coroutine[Any, ANy, None]]

type_ : hikari.commands.CommandType The type of menu command this is.

Only [hikari.commands.CommandType.USER][] and [hikari.commands.CommandType.MESSAGE][]
are valid here.

name The command's name.

This must be between 1 and 32 characters in length.

always_defer Whether the contexts this command is executed with should always be deferred before being passed to the command's callback. default_member_permissions Member permissions necessary to utilize this command by default.

If this is [None][] then the configuration for the parent component or client
will be used.

default_to_ephemeral Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as [None][] then the default set on the parent command(s),
component or client will be in effect.

dm_enabled Whether this command is enabled in DMs with the bot.

If this is [None][] then the configuration for the parent component or client
will be used.

is_global Whether this command is a global command.

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.MenuCommandCallbackSig], MenuCommand]

The decorator callback used to make a tanjun.MenuCommand.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand, tanjun.SlashCommand) and will manage loading the other command into a component when using tanjun.Component.load_from_scope.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name isn't in the length range of 1 to 32.
  • If the command name has uppercase characters.

set_ephemeral_default(state) #

Set whether this command's responses should default to ephemeral.

PARAMETER DESCRIPTION
state

Whether this command's responses should default to ephemeral. This will be overridden by any response calls which specify flags.

Setting this to None will let the default set on the parent command(s), component or client propagate and decide the ephemeral default for contexts used by this command.

TYPE: typing.Optional[bool]

RETURNS DESCRIPTION
Self

This command to allow for chaining.

wrapped_command() property #

The command object this wraps, if any.

as_message_menu(name, /, *, always_defer=False, default_member_permissions=None, default_to_ephemeral=None, dm_enabled=None, is_global=True) #

Build a message tanjun.MenuCommand by decorating a function.

Note

Under the standard implementation, is_global is used to determine whether the command should be bulk set by [tanjun.Client.declare_global_commands][] or when declare_global_commands is True

Note

If you want your first response to be ephemeral while using always_defer, you must set default_to_ephemeral to True.

Examples:

@as_message_menu("message")
async def message_command(self, ctx: tanjun.abc.MenuContext, message: hikari.Message) -> None:
    await ctx.respond(
        embed=hikari.Embed(title="Message content", description=message.content or "N/A")
    )
PARAMETER DESCRIPTION
name

The command's name.

This must be between 1 and 32 characters in length.

TYPE: str

always_defer

Whether the contexts this command is executed with should always be deferred before being passed to the command's callback.

TYPE: bool DEFAULT: False

default_member_permissions

Member permissions necessary to utilize this command by default.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Union[hikari.Permissions, int, None] DEFAULT: None

default_to_ephemeral

Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as None then the default set on the parent command(s), component or client will be in effect.

TYPE: typing.Optional[bool] DEFAULT: None

dm_enabled

Whether this command is enabled in DMs with the bot.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Optional[bool] DEFAULT: None

is_global

Whether this command is a global command.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.MenuCommandCallbackSig], MenuCommand]

The decorator callback used to make a tanjun.MenuCommand.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand, tanjun.SlashCommand) and will manage loading the other command into a component when using tanjun.Component.load_from_scope.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name isn't in the length range of 1 to 32.
  • If the command name has uppercase characters.

as_user_menu(name, /, *, always_defer=False, default_member_permissions=None, default_to_ephemeral=None, dm_enabled=None, is_global=True) #

Build a user tanjun.MenuCommand by decorating a function.

Note

Under the standard implementation, is_global is used to determine whether the command should be bulk set by [tanjun.Client.declare_global_commands][] or when declare_global_commands is True

Note

If you want your first response to be ephemeral while using always_defer, you must set default_to_ephemeral to True.

Examples:

@as_user_menu("user")
async def user_command(
    self,
    ctx: tanjun.abc.MenuContext,
    user: hikari.User | hikari.InteractionMember,
) -> None:
    await ctx.respond(f"Hello {user}")
PARAMETER DESCRIPTION
name

The command's name.

This must be between 1 and 32 characters in length.

TYPE: str

always_defer

Whether the contexts this command is executed with should always be deferred before being passed to the command's callback.

TYPE: bool DEFAULT: False

default_member_permissions

Member permissions necessary to utilize this command by default.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Union[hikari.Permissions, int, None] DEFAULT: None

default_to_ephemeral

Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as None then the default set on the parent command(s), component or client will be in effect.

TYPE: typing.Optional[bool] DEFAULT: None

dm_enabled

Whether this command is enabled in DMs with the bot.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Optional[bool] DEFAULT: None

is_global

Whether this command is a global command.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.MenuCommandCallbackSig], MenuCommand]

The decorator callback used to make a tanjun.MenuCommand.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand, tanjun.SlashCommand) and will manage loading the other command into a component when using tanjun.Component.load_from_scope.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name isn't in the length range of 1 to 32.
  • If the command name has uppercase characters.

tanjun.commands.message #

Message command implementations.

MessageCommand #

Bases: base.PartialCommand[tanjun.MessageContext], tanjun.MessageCommand[_CommandCallbackSigT]

Standard implementation of a message command.

__init__(callback, name, /, *names, validate_arg_keys=True, _wrapped_command=None) #

Initialise a message command.

PARAMETER DESCRIPTION
callback

Callback to execute when the command is invoked.

This should be an asynchronous callback which takes one positional argument of type tanjun.abc.MessageContext, returns None and may use dependency injection to access other services.

TYPE: collections.abc.Callable[[tanjun.abc.MessageContext, ...], collections.abc.Coroutine[None]]

name

The command name.

TYPE: str

*names

Variable positional arguments of other names for the command.

TYPE: str DEFAULT: ()

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

wrapped_command() property #

The command object this wraps, if any.

MessageCommandGroup #

Bases: MessageCommand[_CommandCallbackSigT], tanjun.MessageCommandGroup[_CommandCallbackSigT]

Standard implementation of a message command group.

__init__(callback, name, /, *names, strict=False, validate_arg_keys=True, _wrapped_command=None) #

Initialise a message command group.

PARAMETER DESCRIPTION
callback

Callback to execute when the command is invoked.

This should be an asynchronous callback which takes one positional argument of type tanjun.abc.MessageContext, returns None and may use dependency injection to access other services.

TYPE: collections.abc.Callable[[tanjun.abc.MessageContext, ...], collections.abc.Coroutine[None]]

name

The command name.

TYPE: str

*names

Variable positional arguments of other names for the command.

TYPE: str DEFAULT: ()

strict

Whether this command group should only allow commands without spaces in their names.

This allows for a more optimised command search pattern to be used and enforces that command names are unique to a single command within the group.

TYPE: bool DEFAULT: False

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

add_command(command) #

Add a command to this group.

PARAMETER DESCRIPTION
command

The command to add.

TYPE: tanjun.MessageCommand[typing.Any]

RETURNS DESCRIPTION
Self

The group instance to enable chained calls.

RAISES DESCRIPTION
ValueError

If one of the command's names is already registered in a strict command group.

as_sub_command(name, /, *names, validate_arg_keys=True) #

Build a message command in this group from a decorated callback.

PARAMETER DESCRIPTION
name

The command name.

TYPE: str

*names

Variable positional arguments of other names for the command.

TYPE: str DEFAULT: ()

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.CommandCallbackSig], MessageCommand]

The decorator callback used to make a sub-command.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand, tanjun.SlashCommand).

as_sub_group(name, /, *names, strict=False, validate_arg_keys=True) #

Build a message command group in this group from a decorated callback.

PARAMETER DESCRIPTION
name

The command name.

TYPE: str

*names

Variable positional arguments of other names for the command.

TYPE: str DEFAULT: ()

strict

Whether this command group should only allow commands without spaces in their names.

This allows for a more optimised command search pattern to be used and enforces that command names are unique to a single command within the group.

TYPE: bool DEFAULT: False

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.CommandCallbackSig], MessageCommand]

The decorator callback used to make a sub-command group.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand, tanjun.SlashCommand).

as_message_command(name, /, *names, validate_arg_keys=True) #

Build a message command from a decorated callback.

PARAMETER DESCRIPTION
name

The command name.

TYPE: str

*names

Variable positional arguments of other names for the command.

TYPE: str DEFAULT: ()

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.CommandCallbackSig], MessageCommand]

The decorator callback used to make a tanjun.MessageCommand.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand, tanjun.SlashCommand) and will manage loading the other command into a component when using tanjun.Component.load_from_scope.

as_message_command_group(name, /, *names, strict=False, validate_arg_keys=True) #

Build a message command group from a decorated callback.

PARAMETER DESCRIPTION
name

The command name.

TYPE: str

*names

Variable positional arguments of other names for the command.

TYPE: str DEFAULT: ()

strict

Whether this command group should only allow commands without spaces in their names.

This allows for a more optimised command search pattern to be used and enforces that command names are unique to a single command within the group.

TYPE: bool DEFAULT: False

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.CommandCallbackSig], MessageCommand]

The decorator callback used to make a tanjun.MessageCommandGroup.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand, tanjun.SlashCommand) and will manage loading the other command into a component when using tanjun.Component.load_from_scope.

tanjun.commands.slash #

Slash command implementations.

UNDEFINED_DEFAULT = object() module-attribute #

Singleton used for marking slash command defaults as undefined.

BaseSlashCommand #

Bases: base.PartialCommand[tanjun.SlashContext], tanjun.BaseSlashCommand

Base class used for the standard slash command implementations.

set_ephemeral_default(state) #

Set whether this command's responses should default to ephemeral.

PARAMETER DESCRIPTION
state

Whether this command's responses should default to ephemeral. This will be overridden by any response calls which specify flags.

Setting this to None will let the default set on the parent command(s), component or client propagate and decide the ephemeral default for contexts used by this command.

TYPE: typing.Optional[bool]

RETURNS DESCRIPTION
Self

This command to allow for chaining.

SlashCommand #

Bases: BaseSlashCommand, tanjun.SlashCommand[_CommandCallbackSigT]

Standard implementation of a slash command.

__init__(callback, name, description, /, *, always_defer=False, default_member_permissions=None, default_to_ephemeral=None, dm_enabled=None, is_global=True, sort_options=True, validate_arg_keys=True, _wrapped_command=None) #

Initialise a slash command.

Note

Under the standard implementation, is_global is used to determine whether the command should be bulk set by [tanjun.Client.declare_global_commands][] or when declare_global_commands is True

Warning

default_member_permissions, "dm_enabled" and is_global are ignored for commands within slash command groups.

Note

If you want your first response to be ephemeral while using always_defer, you must set default_to_ephemeral to True.

PARAMETER DESCRIPTION
callback

Callback to execute when the command is invoked.

This should be an asynchronous callback which takes one positional argument of type tanjun.abc.SlashContext, returns None and may use dependency injection to access other services.

TYPE: collections.abc.Callable[[tanjun.abc.SlashContext, ...], collections.abc.Coroutine[Any, Any, None]]

name

The command's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The command's description. This should be inclusively between 1-100 characters in length.

TYPE: str

always_defer

Whether the contexts this command is executed with should always be deferred before being passed to the command's callback.

TYPE: bool DEFAULT: False

default_member_permissions

Member permissions necessary to utilize this command by default.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Union[hikari.Permissions, int, None] DEFAULT: None

default_to_ephemeral

Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as None then the default set on the parent command(s), component or client will be in effect.

TYPE: typing.Optional[bool] DEFAULT: None

dm_enabled

Whether this command is enabled in DMs with the bot.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Optional[bool] DEFAULT: None

is_global

Whether this command is a global command.

TYPE: bool DEFAULT: True

sort_options

Whether this command should sort its set options based on whether they're required.

If this is True then the options are re-sorted to meet the requirement from Discord that required command options be listed before optional ones.

TYPE: bool DEFAULT: True

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the command name has uppercase characters.
  • If the description is over 100 characters long.

add_attachment_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add an attachment option to the slash command.

Note

This will result in options of type hikari.messages.Attachment.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

PARAMETER DESCRIPTION
default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str]

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used and the coverters field will be ignored.

TYPE: bool

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the command already has 25 options.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_bool_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a boolean option to a slash command.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the command already has 25 options.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_channel_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, types=None, pass_as_kwarg=True) #

Add a channel option to a slash command.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

types

A collection of the channel classes and types this option should accept.

If left as None or empty then the option will allow all channel types.

TYPE: typing.Optional[collections.Collection[typing.Union[type[hikari.PartialChannel], int]]] DEFAULT: None

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the command already has 25 options.
  • If an invalid type is passed in types.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_float_option(name, description, /, *, always_float=True, autocomplete=None, choices=None, converters=(), default=UNDEFINED_DEFAULT, key=None, min_value=None, max_value=None, pass_as_kwarg=True, _stack_level=0) #

Add a float option to a slash command.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

always_float

If this is set to True then the value will always be converted to a float (this will happen before it's passed to converters).

This masks behaviour from Discord where we will either be provided a float or int dependent on what the user provided.

TYPE: bool DEFAULT: True

autocomplete

The autocomplete callback for the option.

More information on this callback's signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type float.

TYPE: typing.Optional[tanjun.AutocompleteCallbackSig] DEFAULT: None

choices

The option's choices.

This is a mapping of [option_name, option_value] where option_name should be a string of up to 100 characters and option_value should be a float.

TYPE: typing.Optional[collections.Mapping[str, float]] DEFAULT: None

converters

The option's converters.

This may be either one or multiple converter callbacks used to convert the option's value to the final form. If no converters are provided then the raw value will be passed.

Only the first converter to pass will be used.

TYPE: typing.Union[collections.Collection[ConverterSig], ConverterSig] DEFAULT: ()

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

min_value

The option's (inclusive) minimum value.

TYPE: typing.Optional[float] DEFAULT: None

max_value

The option's (inclusive) maximum value.

TYPE: typing.Optional[float] DEFAULT: None

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used and the fields coverters, and always_float will be ignored.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the option has more than 25 choices.
  • If the command already has 25 options.
  • If min_value is greater than max_value.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_int_option(name, description, /, *, autocomplete=None, choices=None, converters=(), default=UNDEFINED_DEFAULT, key=None, min_value=None, max_value=None, pass_as_kwarg=True, _stack_level=0) #

Add an integer option to the slash command.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

autocomplete

The autocomplete callback for the option.

More information on this callback's signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type int.

TYPE: typing.Optional[tanjun.AutocompleteCallbackSig] DEFAULT: None

choices

The option's choices.

This is a mapping of [option_name, option_value] where option_name should be a string of up to 100 characters and option_value should be an integer.

TYPE: typing.Optional[collections.Mapping[str, int]] DEFAULT: None

converters

The option's converters.

This may be either one or multiple converter callbacks used to convert the option's value to the final form. If no converters are provided then the raw value will be passed.

Only the first converter to pass will be used.

TYPE: typing.Union[collections.Collection[ConverterSig], ConverterSig] DEFAULT: ()

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

min_value

The option's (inclusive) minimum value.

TYPE: typing.Optional[int] DEFAULT: None

max_value

The option's (inclusive) maximum value.

TYPE: typing.Optional[int] DEFAULT: None

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used and the coverters field will be ignored.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the option has more than 25 choices.
  • If the command already has 25 options.
  • If min_value is greater than max_value.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_member_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None) #

Add a member option to a slash command.

Warning

Unlike the other options, this is an artificial option which adds a restraint to the USER option type and therefore cannot have pass_as_kwarg set to False as this artificial constraint isn't present when its not being passed as a keyword argument.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the command already has 25 options.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_mentionable_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a mentionable option to a slash command.

Note

This may target roles, guild members or users and results in hikari.User | hikari.InteractionMember | hikari.Role.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the command already has 25 options.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_role_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a role option to a slash command.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the command already has 25 options.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_str_option(name, description, /, *, autocomplete=None, choices=None, converters=(), default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True, _stack_level=0) #

Add a string option to the slash command.

Note

As a shorthand, choices also supports passing a list of strings rather than a dict of names to values (each string will used as both the choice's name and value with the names being capitalised).

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

autocomplete

The autocomplete callback for the option.

More information on this callback's signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type str.

TYPE: typing.Optional[tanjun.AutocompleteCallbackSig] DEFAULT: None

choices

The option's choices.

This either a mapping of [option_name, option_value] where both option_name and option_value should be strings of up to 100 characters or a sequence of strings where the string will be used for both the choice's name and value.

TYPE: typing.Union[collections.Mapping[str, str], collections.Sequence[str], None] DEFAULT: None

converters

The option's converters.

This may be either one or multiple converter callbacks used to convert the option's value to the final form. If no converters are provided then the raw value will be passed.

Only the first converter to pass will be used.

TYPE: typing.Union[collections.Sequence[ConverterSig], ConverterSig] DEFAULT: ()

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used and the coverters field will be ignored.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the option has more than 25 choices.
  • If the command already has 25 options.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

add_user_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a user option to a slash command.

Note

This may result in hikari.interactions.base_interactions.InteractionMember or hikari.users.User if the user isn't in the current guild or if this command was executed in a DM channel.

PARAMETER DESCRIPTION
name

The option's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The option's description.

This should be inclusively between 1-100 characters in length.

TYPE: str

default

The option's default value.

If this is left as undefined then this option will be required.

TYPE: typing.Any DEFAULT: UNDEFINED_DEFAULT

key

Name of the argument this option's value should be passed to.

This defaults to the first name provided in name and is no-op if pass_as_kwarg is False.

TYPE: typing.Optional[str] DEFAULT: None

pass_as_kwarg

Whether or not to pass this option as a keyword argument to the command callback.

If False is passed here then default will only decide whether the option is required without the actual value being used.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the option name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the option name has uppercase characters.
  • If the option description is over 100 characters in length.
  • If the option has more than 25 choices.
  • If the command already has 25 options.
  • If name isn't valid for this command's callback when validate_arg_keys is True.

set_float_autocomplete(name, callback) #

Set the autocomplete callback for a float option.

PARAMETER DESCRIPTION
name

The option's name.

TYPE: str

callback

The autocomplete callback for the option.

More information on this callback's signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type float.

Passing None here will remove the autocomplete callback for the option.

TYPE: typing.Optional[tanjun.AutocompleteCallbackSig]

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
KeyError

Raises a key error if the option doesn't exist.

TypeError

Raises a type error if the option isn't of type float.

set_int_autocomplete(name, callback) #

Set the autocomplete callback for a string option.

PARAMETER DESCRIPTION
name

The option's name.

TYPE: str

callback

The autocomplete callback for the option.

More information on this callback's signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type str.

Passing None here will remove the autocomplete callback for the option.

TYPE: tanjun.AutocompleteCallbackSig

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
KeyError

Raises a key error if the option doesn't exist.

TypeError

Raises a type error if the option isn't of type str.

set_str_autocomplete(name, callback) #

Set the autocomplete callback for a str option.

PARAMETER DESCRIPTION
name

The option's name.

TYPE: str

callback

The autocomplete callback for the option.

More information on this callback's signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type str.

Passing None here will remove the autocomplete callback for the option.

TYPE: tanjun.AutocompleteCallbackSig

RETURNS DESCRIPTION
Self

The command object for chaining.

RAISES DESCRIPTION
KeyError

Raises a key error if the option doesn't exist.

TypeError

Raises a type error if the option isn't of type str.

with_float_autocomplete(name) #

Set the autocomplete callback for a float option through a decorator call.

PARAMETER DESCRIPTION
name

The option's name.

TYPE: str

RETURNS DESCRIPTION
Collections.abc.Callable[[tanjun.abc.AutocompleteCallbackSig], tanjun.abc.AutocompleteCallbackSig]

Decorator callback used to capture the autocomplete callback.

More information on the autocomplete signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type float.

RAISES DESCRIPTION
KeyError

Raises a key error if the option doesn't exist.

TypeError

Raises a type error if the option isn't of type float.

with_int_autocomplete(name) #

Set the autocomplete callback for a integer option through a decorator call.

PARAMETER DESCRIPTION
name

The option's name.

TYPE: str

RETURNS DESCRIPTION
Collections.abc.Callable[[tanjun.abc.AutocompleteCallbackSig], tanjun.abc.AutocompleteCallbackSig]

Decorator callback used to capture the autocomplete callback.

More information on the autocomplete signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type int.

RAISES DESCRIPTION
KeyError

Raises a key error if the option doesn't exist.

TypeError

Raises a type error if the option isn't of type int.

with_str_autocomplete(name) #

Set the autocomplete callback for a string option through a decorator call.

PARAMETER DESCRIPTION
name

The option's name.

TYPE: str

RETURNS DESCRIPTION
Collections.abc.Callable[[tanjun.abc.AutocompleteCallbackSig], tanjun.abc.AutocompleteCallbackSig]

Decorator callback used to capture the autocomplete callback.

More information on the autocomplete signature can be found at tanjun.abc.AutocompleteCallbackSig and the 2nd positional argument should be of type str.

RAISES DESCRIPTION
KeyError

Raises a key error if the option doesn't exist.

TypeError

Raises a type error if the option isn't of type str.

wrapped_command() property #

The command object this wraps, if any.

SlashCommandGroup #

Bases: BaseSlashCommand, tanjun.SlashCommandGroup

Standard implementation of a slash command group.

Note

Unlike message command groups, slash command groups cannot be callable functions themselves.

__init__(name, description, /, *, default_member_permissions=None, default_to_ephemeral=None, dm_enabled=None, is_global=True) #

Initialise a slash command group.

Note

Under the standard implementation, is_global is used to determine whether the command should be bulk set by [tanjun.Client.declare_global_commands][] or when declare_global_commands is True

Warning

default_member_permissions, "dm_enabled" and is_global are ignored for commands groups within another slash command groups.

PARAMETER DESCRIPTION
name

The name of the command group.

This must match the regex ^[\w-]{1,32}$ in Unicode mode and be lowercase.

TYPE: str

description

The description of the command group.

TYPE: str

default_member_permissions

Member permissions necessary to utilize this command by default.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Union[hikari.Permissions, int, None] DEFAULT: None

default_to_ephemeral

Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as None then the default set on the parent command(s), component or client will be in effect.

TYPE: typing.Optional[bool] DEFAULT: None

dm_enabled

Whether this command is enabled in DMs with the bot.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Optional[bool] DEFAULT: None

is_global

Whether this command is a global command.

TYPE: bool DEFAULT: True

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the command name has uppercase characters.
  • If the description is over 100 characters long.

add_command(command) #

Add a slash command to this group.

Warning

Command groups are only supported within top-level groups.

PARAMETER DESCRIPTION
command

Command to add to this group.

TYPE: tanjun.BaseSlashCommand

RETURNS DESCRIPTION
Self

Object of this group to enable chained calls.

as_sub_command(name, description, /, *, always_defer=False, default_to_ephemeral=None, sort_options=True, validate_arg_keys=True) #

Build a tanjun.SlashCommand in this command group by decorating a function.

Note

If you want your first response to be ephemeral while using always_defer, you must set default_to_ephemeral to True.

PARAMETER DESCRIPTION
name

The command's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The command's description. This should be inclusively between 1-100 characters in length.

TYPE: str

always_defer

Whether the contexts this command is executed with should always be deferred before being passed to the command's callback.

TYPE: bool DEFAULT: False

default_to_ephemeral

Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as None then the default set on the parent command(s), component or client will be in effect.

TYPE: typing.Optional[bool] DEFAULT: None

sort_options

Whether this command should sort its set options based on whether they're required.

If this is True then the options are re-sorted to meet the requirement from Discord that required command options be listed before optional ones.

TYPE: bool DEFAULT: True

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.CommandCallbackSig], SlashCommand]

The decorator callback used to make a sub-command.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand tanjun.SlashCommand).

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the command name has uppercase characters.
  • If the description is over 100 characters long.

make_sub_group(name, description, /, *, default_to_ephemeral=None) #

Create a sub-command group in this group.

Note

Unlike message command groups, slash command groups cannot be callable functions themselves.

PARAMETER DESCRIPTION
name

The name of the command group.

This must match the regex ^[\w-]{1,32}$ in Unicode mode and be lowercase.

TYPE: str

description

The description of the command group.

TYPE: str

default_to_ephemeral

Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as None then the default set on the parent command(s), component or client will be in effect.

TYPE: typing.Optional[bool] DEFAULT: None

RETURNS DESCRIPTION
SlashCommandGroup

The created sub-command group.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the command name has uppercase characters.
  • If the description is over 100 characters long.

remove_command(command) #

Remove a command from this group.

PARAMETER DESCRIPTION
command

Command to remove from this group.

TYPE: tanjun.BaseSlashCommand

RETURNS DESCRIPTION
Self

Object of this group to enable chained calls.

with_command(command) #

Add a slash command to this group through a decorator call.

PARAMETER DESCRIPTION
command

Command to add to this group.

TYPE: tanjun.abc.BaseSlashCommand

RETURNS DESCRIPTION
tanjun.abc.BaseSlashCommand

Command which was added to this group.

as_slash_command(name, description, /, *, always_defer=False, default_member_permissions=None, default_to_ephemeral=None, dm_enabled=None, is_global=True, sort_options=True, validate_arg_keys=True) #

Build a tanjun.SlashCommand by decorating a function.

Note

Under the standard implementation, is_global is used to determine whether the command should be bulk set by [tanjun.Client.declare_global_commands][] or when declare_global_commands is True

Warning

default_member_permissions, "dm_enabled" and is_global are ignored for commands within slash command groups.

Note

If you want your first response to be ephemeral while using always_defer, you must set default_to_ephemeral to True.

Examples:

@as_slash_command("ping", "Get the bot's latency")
async def ping_command(self, ctx: tanjun.abc.SlashContext) -> None:
    start_time = time.perf_counter()
    await ctx.rest.fetch_my_user()
    time_taken = (time.perf_counter() - start_time) * 1_000
    await ctx.respond(f"PONG\n - REST: {time_taken:.0f}mss")
PARAMETER DESCRIPTION
name

The command's name.

This must match the regex ^[\w-]{1,32} in Unicode mode and be lowercase.

TYPE: str

description

The command's description. This should be inclusively between 1-100 characters in length.

TYPE: str

always_defer

Whether the contexts this command is executed with should always be deferred before being passed to the command's callback.

TYPE: bool DEFAULT: False

default_member_permissions

Member permissions necessary to utilize this command by default.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Union[hikari.Permissions, int, None] DEFAULT: None

default_to_ephemeral

Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as None then the default set on the parent command(s), component or client will be in effect.

TYPE: typing.Optional[bool] DEFAULT: None

dm_enabled

Whether this command is enabled in DMs with the bot.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Optional[bool] DEFAULT: None

is_global

Whether this command is a global command.

TYPE: bool DEFAULT: True

sort_options

Whether this command should sort its set options based on whether they're required.

If this is True then the options are re-sorted to meet the requirement from Discord that required command options be listed before optional ones.

TYPE: bool DEFAULT: True

validate_arg_keys

Whether to validate that option keys match the command callback's signature.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.CommandCallbackSig], SlashCommand]

The decorator callback used to make a tanjun.SlashCommand.

This can either wrap a raw command callback or another callable command instance (e.g. tanjun.MenuCommand, tanjun.MessageCommand tanjun.SlashCommand) and will manage loading the other command into a component when using tanjun.Component.load_from_scope.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the command name has uppercase characters.
  • If the description is over 100 characters long.

slash_command_group(name, description, /, *, default_member_permissions=None, default_to_ephemeral=None, dm_enabled=None, is_global=True) #

Create a slash command group.

Note

Unlike message command groups, slash command groups cannot be callable functions themselves.

Warning

default_member_permissions, "dm_enabled" and is_global are ignored for command groups within other slash command groups.

Note

Under the standard implementation, is_global is used to determine whether the command should be bulk set by [tanjun.Client.declare_global_commandsadd_command or when declare_global_commands is True

Examples:

Sub-commands can be added to the created slash command object through the following decorator based approach:

help_group = tanjun.slash_command_group("help", "get help")

@help_group.with_command
@tanjun.with_str_slash_option("command_name", "command name")
@tanjun.as_slash_command("command", "Get help with a command")
async def help_command_command(ctx: tanjun.abc.SlashContext, command_name: str) -> None:
    ...

@help_group.with_command
@tanjun.as_slash_command("me", "help me")
async def help_me_command(ctx: tanjun.abc.SlashContext) -> None:
    ...

component = tanjun.Component().add_slash_command(help_group)
PARAMETER DESCRIPTION
name

The name of the command group.

This must match the regex ^[\w-]{1,32}$ in Unicode mode and be lowercase.

TYPE: str

description

The description of the command group.

TYPE: str

default_member_permissions

Member permissions necessary to utilize this command by default.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Union[hikari.Permissions, int, None] DEFAULT: None

default_to_ephemeral

Whether this command's responses should default to ephemeral unless flags are set to override this.

If this is left as None then the default set on the parent command(s), component or client will be in effect.

TYPE: typing.Optional[bool] DEFAULT: None

dm_enabled

Whether this command is enabled in DMs with the bot.

If this is None then the configuration for the parent component or client will be used.

TYPE: typing.Optional[bool] DEFAULT: None

is_global

Whether this command is a global command.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
SlashCommandGroup

The command group.

RAISES DESCRIPTION
ValueError

Raises a value error for any of the following reasons:

  • If the command name doesn't match the regex ^[\w-]{1,32}$ (Unicode mode).
  • If the command name has uppercase characters.
  • If the description is over 100 characters long.

with_attachment_slash_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add an attachment option to a slash command.

For more information on this function's parameters see tanjun.SlashCommand.add_attachment_option.

Examples:

@with_attachment_slash_option("name", "A name.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, name: hikari.Attachment) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_bool_slash_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a boolean option to a slash command.

For information on this function's parameters see tanjun.SlashCommand.add_bool_option.

Examples:

@with_bool_slash_option("flag", "Whether this flag should be enabled.", default=False)
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, flag: bool) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_channel_slash_option(name, description, /, *, types=None, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a channel option to a slash command.

For information on this function's parameters see tanjun.SlashCommand.add_channel_option.

Examples:

@with_channel_slash_option("channel", "channel to target.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, channel: hikari.InteractionChannel) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_float_slash_option(name, description, /, *, always_float=True, autocomplete=None, choices=None, converters=(), default=UNDEFINED_DEFAULT, key=None, min_value=None, max_value=None, pass_as_kwarg=True) #

Add a float option to a slash command.

For information on this function's parameters see tanjun.SlashCommand.add_float_option.

Examples:

@with_float_slash_option("float_value", "Float value.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, float_value: float) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_int_slash_option(name, description, /, *, autocomplete=None, choices=None, converters=(), default=UNDEFINED_DEFAULT, key=None, min_value=None, max_value=None, pass_as_kwarg=True) #

Add an integer option to a slash command.

For information on this function's parameters see tanjun.SlashCommand.add_int_option.

Examples:

@with_int_slash_option("int_value", "Int value.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, int_value: int) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_member_slash_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None) #

Add a member option to a slash command.

For information on this function's arguments see tanjun.SlashCommand.add_member_option.

Examples:

@with_member_slash_option("member", "member to target.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, member: hikari.InteractionMember) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_mentionable_slash_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a mentionable option to a slash command.

For information on this function's arguments see tanjun.SlashCommand.add_mentionable_option.

Note

This may target roles, guild members or users and results in hikari.User | hikari.InteractionMember | hikari.Role.

Examples:

@with_mentionable_slash_option("mentionable", "Mentionable entity to target.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, mentionable: [Role, InteractionMember, User]) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_role_slash_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a role option to a slash command.

For information on this function's parameters see tanjun.SlashCommand.add_role_option.

Examples:

@with_role_slash_option("role", "Role to target.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, role: hikari.Role) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_str_slash_option(name, description, /, *, autocomplete=None, choices=None, converters=(), default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a string option to a slash command.

For more information on this function's parameters see tanjun.commands.SlashCommand.add_str_option.

Examples:

@with_str_slash_option("name", "A name.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, name: str) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.

with_user_slash_option(name, description, /, *, default=UNDEFINED_DEFAULT, key=None, pass_as_kwarg=True) #

Add a user option to a slash command.

For information on this function's parameters see tanjun.SlashCommand.add_user_option.

Note

This may result in hikari.interactions.base_interactions.InteractionMember or hikari.users.User if the user isn't in the current guild or if this command was executed in a DM channel.

Examples:

@with_user_slash_option("user", "user to target.")
@as_slash_command("command", "A command")
async def command(self, ctx: tanjun.abc.SlashContext, user: Union[InteractionMember, User]) -> None:
    ...
RETURNS DESCRIPTION
collections.abc.Callable[[_SlashCommandT], _SlashCommandT]

Decorator callback which adds the option to the command.