[][src]Attribute Macro command_attr::command

#[command]

The heart of the attribute-based framework.

This is a function attribute macro. Using this on other Rust constructs won't work.

Options

To alter how the framework will interpret the command, you can provide options as attributes following this #[command] macro.

Each option has its own kind of data to stock and manipulate with. They're given to the option either with the #[option(...)] or #[option = ...] syntaxes. If an option doesn't require for any data to be supplied, then it's simply an empty #[option].

If the input to the option is malformed, the macro will give you can error, describing the correct method for passing data, and what it should be.

The list of available options, is, as follows:

SyntaxDescriptionArgument explanation
#[checks(identifiers)]Preconditions that must met before the command's execution.identifiers is a comma separated list of identifiers referencing functions marked by the #[check] macro
#[aliases(names)]Alternative names to refer to this command.names is a comma separated list of desired aliases.
#[description(desc)]
#[description = desc]
The command's description or summary.desc is a string describing the command.
#[usage(use)]
#[usage = use]
The command's intended usage.use is a string stating the schema for the command's usage.
#[example(ex)]
#[example = ex]
An example of the command's usage. May be called multiple times to add many examples at once.ex is a string
#[delimiters(delims)]Argument delimiters specific to this command. Overrides the global list of delimiters in the framework.delims is a comma separated list of strings
#[min_args(min)]
#[max_args(max)]
#[num_args(min_and_max)]
The expected length of arguments that the command must receive in order to function correctly.min, max and min_and_max are 16-bit, unsigned integers.
#[required_permissions(perms)]Set of permissions the user must possess.perms is a comma separated list of permission names.
These can be found at Discord's official documentation.
#[allowed_roles(roles)]Set of roles the user must possess.roles is a comma separated list of role names.
#[help_available]
#[help_available(b)]
If the command should be displayed in the help message.b is a boolean. If no boolean is provided, the value is assumed to be true.
#[only_in(ctx)]Which environment the command can be executed in.ctx is a string with the accepted values guild/guilds and dm/dms (Direct Message).
#[bucket(name)]
#[bucket = name]
What bucket will impact this command.name is a string containing the bucket's name.
Refer to the bucket example in the standard framework for its usage.
#[owners_only]
#[owners_only(b)]
If this command is exclusive to owners.b is a boolean. If no boolean is provided, the value is assumed to be true.
#[owner_privilege]
#[owner_privilege(b)]
If owners can bypass certain options.b is a boolean. If no boolean is provided, the value is assumed to be true.
#[sub_commands(commands)]The sub or children commands of this command. They are executed in the form: this-command sub-command.commands is a comma separated list of identifiers referencing functions marked by the #[command] macro.

Documentation comments (///) applied onto the function are interpreted as sugar for the #[description] option. When more than one application of the option is performed, the text is delimited by newlines. This mimics the behaviour of regular doc-comments, which are sugar for the #[doc = "..."] attribute.

Notes

The name of the command is parsed from the applied function, or may be specified inside the #[command] attribute, a lá #[command("foobar")].

This macro attribute generates static instances of Command and CommandOptions, conserving the provided options.

The names of the instances are all uppercased names of the command name. For example, with a name of "foo":

This example is not tested
pub static FOO_COMMAND_OPTIONS: CommandOptions = CommandOptions { ... };
pub static FOO_COMMAND: Command = Command { options: FOO_COMMAND_OPTIONS, ... };