Trait twilight_interactions::command::CreateCommand
source · [−]pub trait CreateCommand: Sized {
const NAME: &'static str;
fn create_command() -> ApplicationCommandData;
}Expand description
Create a slash command from a type.
This trait is used to create commands from command models. A derive macro is provided to automatically implement the traits.
Types and fields documentation
The trait can be derived structs where all fields implement CreateOption
(see the module documentation for a list of supported types)
or enums where variants implements CreateCommand.
Unlike the CommandModel trait, the type its field or variants must have
a description. The description correspond either to the first line of the
documentation comment, or the value of the desc attribute. The type must
also be named with the name attribute.
Example
use twilight_interactions::command::{CreateCommand, ResolvedUser};
#[derive(CreateCommand)]
#[command(name = "hello", desc = "Say hello")]
struct HelloCommand {
/// The message to send.
message: String,
/// The user to send the message to.
user: Option<ResolvedUser>,
}Macro attributes
The macro provide a #[command] attribute to provide additional information.
| Attribute | Type | Location | Description |
|---|---|---|---|
name | str | Type | Name of the command (required). |
desc | str | Type / Field / Variant | Set the subcommand name (required). |
default_permission | bool | Type | Whether the command should be enabled by default. |
rename | str | Field | Use a different option name than the field name. |
autocomplete | bool | Field | Enable autocomplete on this field. |
channel_types | str | Field | Restricts the channel choice to specific types.1 |
max_value, min_value | i64 or f64 | Field | Set the maximum and/or minimum value permitted. |
Example
use twilight_interactions::command::{CreateCommand, ResolvedUser};
#[derive(CreateCommand)]
#[command(name = "hello", desc = "Say hello")]
struct HelloCommand {
/// The message to send.
message: String,
/// The user to send the message to.
user: Option<ResolvedUser>,
}List
ChannelTypenames in snake_case separated by spaces likeguild_text private. ↩
Associated Constants
Required methods
Create an ApplicationCommandData for this type.