Command ABCs#
CallableCommandBase
#
Bases: CommandBase[ClientT, BuilderT]
, CallableCommandProto[ClientT]
A top-level command that can be called directly. Note that this does not include subcommands, as those are options.
autodefer
property
#
autodefer: AutodeferMode
The resolved autodefer configuration for this command.
callback
instance-attribute
#
The callback to invoke when this command is called.
command_type
abstractmethod
property
#
command_type: CommandType
The type of command this object represents.
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.
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 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.
qualified_name
abstractmethod
property
#
The fully qualified name of 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
) -> None | Future[ResponseBuilderT]
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. |
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:
|
CallableCommandProto
#
Bases: CommandProto
, Protocol[ClientT]
A protocol for any command-like object that can be called directly.
This includes commands and subcommands, but not groups or subgroups.
callback
instance-attribute
#
The callback to invoke when this command is called.
command_type
abstractmethod
property
#
command_type: CommandType
The type of command this object represents.
display_name
abstractmethod
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.
hooks
abstractmethod
property
#
hooks: MutableSequence[HookT[ClientT]]
The pre-execution hooks for this command.
name_localizations
instance-attribute
#
The name of the command in different locales.
post_hooks
abstractmethod
property
#
post_hooks: MutableSequence[PostHookT[ClientT]]
The post-execution hooks for this command.
qualified_name
abstractmethod
property
#
The fully qualified name of this command.
__call__
abstractmethod
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. |
invoke
abstractmethod
async
#
invoke(
interaction: CommandInteraction, *args: Any, **kwargs: Any
) -> None | Future[ResponseBuilderT]
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. |
CommandBase
#
Bases: HasErrorHandler[ClientT]
, Hookable[ClientT]
, HasConcurrencyLimiter[ClientT]
, Generic[ClientT, BuilderT]
An abstract base class for all application commands.
This notably does not include subcommands & subgroups as those are in reality options.
autodefer
property
#
autodefer: AutodeferMode
The resolved autodefer configuration for this command.
command_type
abstractmethod
property
#
command_type: CommandType
The type of command this object represents.
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.
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 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.
qualified_name
abstractmethod
property
#
The fully qualified name of 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. |
invoke
abstractmethod
async
#
invoke(
interaction: CommandInteraction, *args: Any, **kwargs: Any
) -> None | Future[ResponseBuilderT]
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:
|
CommandProto
#
Bases: Protocol
A protocol for any command-like object. This includes commands, groups, subgroups, and subcommands.
command_type
abstractmethod
property
#
command_type: CommandType
The type of command this object represents.
display_name
abstractmethod
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.
name_localizations
instance-attribute
#
The name of the command in different locales.
SubCommandBase
#
Bases: OptionBase[ClientT]
, HasErrorHandler[ClientT]
, Hookable[ClientT]
, HasConcurrencyLimiter[ClientT]
, Generic[ClientT, ParentT]
An abstract base class for all slash subcommands and subgroups.
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
abstractmethod
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
abstractmethod
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. |
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.