Slash Commands#
SlashCommand
#
Bases: CallableCommandBase[ClientT, SlashCommandBuilder]
A slash command outside of any group.
autodefer
property
#
autodefer: AutodeferMode
The resolved autodefer configuration for this command.
callback
instance-attribute
#
The callback to invoke when this command is called.
concurrency_limiter
property
writable
#
concurrency_limiter: ConcurrencyLimiterProto[ClientT] | None
The concurrency limiter for this command.
default_permissions
property
#
default_permissions: Permissions | UndefinedType
The resolved default permissions for this command.
description
class-attribute
instance-attribute
#
description: str = 'No description provided.'
The description of this slash command.
description_localizations
class-attribute
instance-attribute
#
The localizations for this command's description.
error_handler
property
writable
#
The error handler for this command.
guilds
class-attribute
instance-attribute
#
guilds: Sequence[Snowflake] | UndefinedType = UNDEFINED
The guilds this command is available in.
instances
property
#
instances: Mapping[Snowflake | None, PartialCommand]
A mapping of guild IDs to command instances. None corresponds to the global instance, if any.
is_nsfw
property
#
is_nsfw: bool
Whether this command is NSFW. If true, the command will only be available in NSFW channels.
name_localizations
class-attribute
instance-attribute
#
The localizations for this command's name.
options
class-attribute
instance-attribute
#
The options of this slash command.
plugin
property
#
plugin: PluginBase[ClientT] | None
The plugin that this command belongs to, if any.
post_hooks
property
#
post_hooks: MutableSequence[PostHookT[ClientT]]
The post-execution hooks for this command.
__call__
async
#
Call the callback of the command with the given context and arguments.
PARAMETER | DESCRIPTION |
---|---|
ctx |
The context to invoke this command with.
TYPE:
|
args |
The positional arguments to pass to the callback.
TYPE:
|
kwargs |
The keyword arguments to pass to the callback. |
add_hook
#
Add a new pre-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns either a HookResult
or
None
can be used as a hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
add_post_hook
#
Add a new post-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns None
can be used as a post-hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The post-execution hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
invoke
async
#
invoke(
interaction: CommandInteraction, *args: Any, **kwargs: Any
) -> Future[ResponseBuilderT] | None
Invoke this command with the given interaction.
PARAMETER | DESCRIPTION |
---|---|
interaction |
The interaction to invoke this command with.
TYPE:
|
args |
The positional arguments to pass to the callback.
TYPE:
|
kwargs |
The keyword arguments to pass to the callback. |
RETURNS | DESCRIPTION |
---|---|
None | Future[ResponseBuilderT]
|
If this is a REST client, returns the response builder. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If this command has not been added to a client. |
make_mention
#
make_mention(*, guild: Snowflakeish | PartialGuild | None = None) -> str
Make a slash mention for this command.
PARAMETER | DESCRIPTION |
---|---|
guild |
The guild the command is registered in. If None, the global command's ID is used.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The slash command mention. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the command has not been published in the given guild or globally. |
publish
async
#
publish(guild: SnowflakeishOr[PartialGuild] | None = None) -> PartialCommand
Publish this command to the given guild, or globally if no guild is provided.
PARAMETER | DESCRIPTION |
---|---|
guild |
The guild to publish this command to. If None, publish globally.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
PartialCommand
|
The published command. |
reset_all_limiters
#
reset_all_limiters(context: Context[ClientT]) -> None
Reset all limiter hooks for this command.
PARAMETER | DESCRIPTION |
---|---|
context |
The context to reset the limiters for.
TYPE:
|
set_concurrency_limiter
#
set_concurrency_limiter(limiter: ConcurrencyLimiterProto[ClientT]) -> Self
Set the concurrency limiter for this object.
set_error_handler
#
set_error_handler(
callback: ErrorHandlerCallbackT[ClientT] | None = None,
) -> (
ErrorHandlerCallbackT[ClientT]
| Callable[[ErrorHandlerCallbackT[ClientT]], ErrorHandlerCallbackT[ClientT]]
)
Decorator to set an error handler for this object. This can be added to commands, groups, or plugins.
This function will be called when an exception is raised during the invocation of a command.
Example
@client.include
@arc.slash_command("foo", "Foo command description")
async def foo(ctx: arc.GatewayContext) -> None:
raise RuntimeError("foo")
@foo.set_error_handler
async def foo_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
if isinstance(exc, RuntimeError):
await ctx.respond("foo failed")
return
raise exc
Warning
Errors that cannot be handled by the error handler should be re-raised. Otherwise they will not propagate to the next error handler.
unpublish
async
#
unpublish(guild: SnowflakeishOr[PartialGuild] | None = None) -> None
Unpublish this command from the given guild, or globally if no guild is provided.
PARAMETER | DESCRIPTION |
---|---|
guild |
The guild to unpublish this command from. If None, unpublish globally.
TYPE:
|
SlashGroup
#
Bases: CommandBase[ClientT, SlashCommandBuilder]
A group for slash subcommands and subgroups.
autodefer
property
#
autodefer: AutodeferMode
The resolved autodefer configuration for this command.
children
class-attribute
instance-attribute
#
children: dict[str, SlashSubCommand[ClientT] | SlashSubGroup[ClientT]] = field(
factory=dict, init=False
)
Subcommands and subgroups that belong to this group.
concurrency_limiter
property
writable
#
concurrency_limiter: ConcurrencyLimiterProto[ClientT] | None
The concurrency limiter for this command.
default_permissions
property
#
default_permissions: Permissions | UndefinedType
The resolved default permissions for this command.
description
class-attribute
instance-attribute
#
description: str = 'No description provided.'
The description of this slash group.
description_localizations
class-attribute
instance-attribute
#
The localizations for this group's description.
error_handler
property
writable
#
The error handler for this command.
guilds
class-attribute
instance-attribute
#
guilds: Sequence[Snowflake] | UndefinedType = UNDEFINED
The guilds this command is available in.
instances
property
#
instances: Mapping[Snowflake | None, PartialCommand]
A mapping of guild IDs to command instances. None corresponds to the global instance, if any.
is_nsfw
property
#
is_nsfw: bool
Whether this command is NSFW. If true, the command will only be available in NSFW channels.
name_localizations
class-attribute
instance-attribute
#
The localizations for this command's name.
plugin
property
#
plugin: PluginBase[ClientT] | None
The plugin that this command belongs to, if any.
post_hooks
property
#
post_hooks: MutableSequence[PostHookT[ClientT]]
The post-execution hooks for this command.
add_hook
#
Add a new pre-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns either a HookResult
or
None
can be used as a hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
add_post_hook
#
Add a new post-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns None
can be used as a post-hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The post-execution hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
include
#
include(
command: SlashSubCommand[ClientT] | None = None,
) -> (
SlashSubCommand[ClientT]
| Callable[[SlashSubCommand[ClientT]], SlashSubCommand[ClientT]]
)
Decorator to add a subcommand to this group.
include_subgroup
#
include_subgroup(
name: str,
description: str = "No description provided.",
*,
autodefer: AutodeferMode | bool | UndefinedType = hikari.UNDEFINED,
name_localizations: Mapping[Locale, str] | None = None,
description_localizations: Mapping[Locale, str] | None = None
) -> SlashSubGroup[ClientT]
Create a subgroup and add it to this group.
PARAMETER | DESCRIPTION |
---|---|
name |
The name of the subgroup.
TYPE:
|
description |
The description of the subgroup
TYPE:
|
autodefer |
If True, all commands in this subgroup will automatically defer if it is taking longer than 2 seconds to respond. If not provided, then this setting will be inherited from the parent.
TYPE:
|
name_localizations |
Localizations for the name of the subgroup |
description_localizations |
Localizations for the description of the subgroup |
invoke
async
#
invoke(
interaction: CommandInteraction, *args: Any, **kwargs: Any
) -> Future[ResponseBuilderT] | None
Invoke this command with the given interaction.
PARAMETER | DESCRIPTION |
---|---|
interaction |
The interaction to invoke this command with.
TYPE:
|
args |
The positional arguments to pass to the callback.
TYPE:
|
kwargs |
The keyword arguments to pass to the callback. |
RETURNS | DESCRIPTION |
---|---|
None | Future[ResponseBuilderT]
|
If this is a REST client, returns the response builder. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If this command has not been added to a client. |
publish
async
#
publish(guild: SnowflakeishOr[PartialGuild] | None = None) -> PartialCommand
Publish this command to the given guild, or globally if no guild is provided.
PARAMETER | DESCRIPTION |
---|---|
guild |
The guild to publish this command to. If None, publish globally.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
PartialCommand
|
The published command. |
set_concurrency_limiter
#
set_concurrency_limiter(limiter: ConcurrencyLimiterProto[ClientT]) -> Self
Set the concurrency limiter for this object.
set_error_handler
#
set_error_handler(
callback: ErrorHandlerCallbackT[ClientT] | None = None,
) -> (
ErrorHandlerCallbackT[ClientT]
| Callable[[ErrorHandlerCallbackT[ClientT]], ErrorHandlerCallbackT[ClientT]]
)
Decorator to set an error handler for this object. This can be added to commands, groups, or plugins.
This function will be called when an exception is raised during the invocation of a command.
Example
@client.include
@arc.slash_command("foo", "Foo command description")
async def foo(ctx: arc.GatewayContext) -> None:
raise RuntimeError("foo")
@foo.set_error_handler
async def foo_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
if isinstance(exc, RuntimeError):
await ctx.respond("foo failed")
return
raise exc
Warning
Errors that cannot be handled by the error handler should be re-raised. Otherwise they will not propagate to the next error handler.
unpublish
async
#
unpublish(guild: SnowflakeishOr[PartialGuild] | None = None) -> None
Unpublish this command from the given guild, or globally if no guild is provided.
PARAMETER | DESCRIPTION |
---|---|
guild |
The guild to unpublish this command from. If None, unpublish globally.
TYPE:
|
SlashSubCommand
#
Bases: SubCommandBase[ClientT, SlashGroup[ClientT] | SlashSubGroup[ClientT]]
, CallableCommandProto[ClientT]
A subcommand of a slash command group.
autodefer
property
#
autodefer: AutodeferMode
The resolved autodefer configuration for this subcommand.
callback
instance-attribute
#
The callback that will be invoked when this subcommand is invoked.
concurrency_limiter
property
writable
#
concurrency_limiter: ConcurrencyLimiterProto[ClientT] | None
The concurrency limiter for this object.
description_localizations
class-attribute
instance-attribute
#
The description of the option in different locales.
display_name
property
#
display_name: str
The display name of this command. This is what is shown in the Discord client.
Note
Slash commands can also be mentioned, see SlashCommand.make_mention.
error_handler
property
writable
#
The error handler for this object.
name_localizations
class-attribute
instance-attribute
#
The name of the option in different locales.
option_type
property
#
option_type: OptionType
The type of the option. Used to register the command.
options
class-attribute
instance-attribute
#
options: MutableMapping[str, CommandOptionBase[ClientT, Any, Any]] = field(
factory=dict
)
The options of this subcommand.
parent
property
#
parent: SlashGroup[ClientT] | SlashSubGroup[ClientT]
The parent of this subcommand.
post_hooks
property
#
post_hooks: MutableSequence[PostHookT[ClientT]]
The post-execution hooks for this object.
__call__
async
#
add_hook
#
Add a new pre-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns either a HookResult
or
None
can be used as a hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
add_post_hook
#
Add a new post-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns None
can be used as a post-hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The post-execution hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
invoke
async
#
invoke(
interaction: CommandInteraction, *args: Any, **kwargs: Any
) -> Future[ResponseBuilderT] | None
Invoke this command with the given context.
PARAMETER | DESCRIPTION |
---|---|
interaction |
The interaction to invoke this command with.
TYPE:
|
args |
The positional arguments to pass to the callback.
TYPE:
|
kwargs |
The keyword arguments to pass to the callback. |
RETURNS | DESCRIPTION |
---|---|
None | Future[ResponseBuilderT]
|
If this is a REST client, returns the response builder. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If this command has not been added to a client. |
make_mention
#
make_mention(guild: Snowflakeish | PartialGuild | None = None) -> str
Make a slash mention for this command.
RETURNS | DESCRIPTION |
---|---|
str
|
The slash command mention. |
reset_all_limiters
#
reset_all_limiters(context: Context[ClientT]) -> None
Reset all limiter hooks for this command.
PARAMETER | DESCRIPTION |
---|---|
context |
The context to reset the limiters for.
TYPE:
|
set_concurrency_limiter
#
set_concurrency_limiter(limiter: ConcurrencyLimiterProto[ClientT]) -> Self
Set the concurrency limiter for this object.
set_error_handler
#
set_error_handler(
callback: ErrorHandlerCallbackT[ClientT] | None = None,
) -> (
ErrorHandlerCallbackT[ClientT]
| Callable[[ErrorHandlerCallbackT[ClientT]], ErrorHandlerCallbackT[ClientT]]
)
Decorator to set an error handler for this object. This can be added to commands, groups, or plugins.
This function will be called when an exception is raised during the invocation of a command.
Example
@client.include
@arc.slash_command("foo", "Foo command description")
async def foo(ctx: arc.GatewayContext) -> None:
raise RuntimeError("foo")
@foo.set_error_handler
async def foo_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
if isinstance(exc, RuntimeError):
await ctx.respond("foo failed")
return
raise exc
Warning
Errors that cannot be handled by the error handler should be re-raised. Otherwise they will not propagate to the next error handler.
to_command_option
#
to_command_option() -> CommandOption
Convert this option to a hikari.CommandOption.
SlashSubGroup
#
Bases: SubCommandBase[ClientT, SlashGroup[ClientT]]
A subgroup of a slash command group.
autodefer
property
#
autodefer: AutodeferMode
The resolved autodefer configuration for this subcommand.
children
class-attribute
instance-attribute
#
children: dict[str, SlashSubCommand[ClientT]] = field(factory=dict, init=False)
Subcommands that belong to this subgroup.
concurrency_limiter
property
writable
#
concurrency_limiter: ConcurrencyLimiterProto[ClientT] | None
The concurrency limiter for this object.
description_localizations
class-attribute
instance-attribute
#
The description of the option in different locales.
display_name
property
#
display_name: str
The display name of this command. This is what is shown in the Discord client.
Note
Slash commands can also be mentioned, see SlashCommand.make_mention.
error_handler
property
writable
#
The error handler for this object.
name_localizations
class-attribute
instance-attribute
#
The name of the option in different locales.
option_type
property
#
option_type: OptionType
The type of the option. Used to register the command.
post_hooks
property
#
post_hooks: MutableSequence[PostHookT[ClientT]]
The post-execution hooks for this object.
add_hook
#
Add a new pre-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns either a HookResult
or
None
can be used as a hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
add_post_hook
#
Add a new post-execution hook to this object.
Any function that takes a Context
as its sole parameter
and returns None
can be used as a post-hook.
PARAMETER | DESCRIPTION |
---|---|
hook |
The post-execution hook to add.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
This object for chaining. |
include
#
include(
command: SlashSubCommand[ClientT] | None = None,
) -> (
SlashSubCommand[ClientT]
| Callable[[SlashSubCommand[ClientT]], SlashSubCommand[ClientT]]
)
First-order decorator to add a subcommand to this group.
reset_all_limiters
#
reset_all_limiters(context: Context[ClientT]) -> None
Reset all limiter hooks for this command.
PARAMETER | DESCRIPTION |
---|---|
context |
The context to reset the limiters for.
TYPE:
|
set_concurrency_limiter
#
set_concurrency_limiter(limiter: ConcurrencyLimiterProto[ClientT]) -> Self
Set the concurrency limiter for this object.
set_error_handler
#
set_error_handler(
callback: ErrorHandlerCallbackT[ClientT] | None = None,
) -> (
ErrorHandlerCallbackT[ClientT]
| Callable[[ErrorHandlerCallbackT[ClientT]], ErrorHandlerCallbackT[ClientT]]
)
Decorator to set an error handler for this object. This can be added to commands, groups, or plugins.
This function will be called when an exception is raised during the invocation of a command.
Example
@client.include
@arc.slash_command("foo", "Foo command description")
async def foo(ctx: arc.GatewayContext) -> None:
raise RuntimeError("foo")
@foo.set_error_handler
async def foo_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
if isinstance(exc, RuntimeError):
await ctx.respond("foo failed")
return
raise exc
Warning
Errors that cannot be handled by the error handler should be re-raised. Otherwise they will not propagate to the next error handler.
to_command_option
#
to_command_option() -> CommandOption
Convert this option to a hikari.CommandOption.
slash_command
#
slash_command(
name: str,
description: str = "No description provided.",
*,
guilds: (
Sequence[PartialGuild | Snowflakeish] | UndefinedType
) = hikari.UNDEFINED,
is_dm_enabled: bool | UndefinedType = hikari.UNDEFINED,
is_nsfw: bool | UndefinedType = hikari.UNDEFINED,
autodefer: bool | AutodeferMode | UndefinedType = hikari.UNDEFINED,
default_permissions: Permissions | UndefinedType = hikari.UNDEFINED,
name_localizations: Mapping[Locale, str] | None = None,
description_localizations: Mapping[Locale, str] | None = None
) -> Callable[[CommandCallbackT[ClientT]], SlashCommand[ClientT]]
A decorator that creates a slash command.
PARAMETER | DESCRIPTION |
---|---|
name |
The name of the slash command.
TYPE:
|
description |
The description of the command
TYPE:
|
guilds |
The guilds this command should be enabled in, if left as undefined, the command is global
TYPE:
|
is_dm_enabled |
If True, the command is usable in direct messages
TYPE:
|
is_nsfw |
If True, the command is only usable in NSFW channels
TYPE:
|
autodefer |
If True, this command will be automatically deferred if it takes longer than 2 seconds to respond
TYPE:
|
default_permissions |
The default permissions required to use this command, these can be overriden by guild admins
TYPE:
|
name_localizations |
Localizations for the name of this command |
description_localizations |
Localizations for the description of this command |
RETURNS | DESCRIPTION |
---|---|
Callable[[Callable[Concatenate[Context[ClientT], ...], Awaitable[None]]], SlashCommand[ClientT]]
|
The decorated slash command. |
!!! note
|
Parameters left as |
slash_subcommand
#
slash_subcommand(
name: str,
description: str = "No description provided.",
*,
autodefer: bool | AutodeferMode | UndefinedType = hikari.UNDEFINED,
name_localizations: Mapping[Locale, str] | None = None,
description_localizations: Mapping[Locale, str] | None = None
) -> Callable[[CommandCallbackT[ClientT]], SlashSubCommand[ClientT]]
A decorator that creates a slash sub command. It should be included in a slash command group.
PARAMETER | DESCRIPTION |
---|---|
name |
The name of the slash command.
TYPE:
|
description |
The description of the command
TYPE:
|
autodefer |
If True, this command will be automatically deferred if it takes longer than 2 seconds to respond If undefined, then this setting will be be inherited from the parent
TYPE:
|
name_localizations |
Localizations for the name of this command |
description_localizations |
Localizations for the description of this command |
RETURNS | DESCRIPTION |
---|---|
Callable[[Callable[Concatenate[Context[ClientT], ...], Awaitable[None]]], SlashCommand[ClientT]]
|
The decorated slash command. |
!!! note
|
Parameters left as |
Example
group = client.include_slash_group("group", "A group of slash commands.")
@group.include
@arc.slash_subcommand(name="hi", description="Say hi!")
async def hi_slashsub(
ctx: arc.GatewayContext,
user: arc.Option[hikari.User, arc.UserParams(description="The user to say hi to.")]
) -> None:
await ctx.respond(f"Hey {user.mention}!")