Message Command#
MessageCommand
#
Bases: CallableCommandBase[ClientT, ContextMenuCommandBuilder]
A context menu command that is invoked by right-clicking a message.
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.
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.
__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. |
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:
|
message_command
#
message_command(
name: str,
*,
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
) -> Callable[[MessageCommandCallbackT[ClientT]], MessageCommand[ClientT]]
A decorator that creates a context-menu command on a message.
Note
Parameters left as hikari.UNDEFINED
will be inherited from the parent plugin or client.
PARAMETER | DESCRIPTION |
---|---|
name |
The name 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 |
Whether this command is enabled in DMs.
TYPE:
|
is_nsfw |
Whether this command is NSFW.
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 for this command. Keep in mind that guild administrators can change this, it should only be used to provide safe defaults.
TYPE:
|
name_localizations |
The localizations for this command's name. |