Trait twilight_interactions::command::CreateCommand [−][src]
pub trait CreateCommand: Sized {
fn create_command() -> ApplicationCommandData;
}Expand description
Create a ApplicationCommandData from a type.
This trait allow to obtain command information from a type. See the module-level documentation to learn more.
Derive macro
A derive macro is provided to implement this trait. The macro only works
with structs with named fields where all field types implement CreateOption.
Macro attributes
The macro provide a #[command] attribute to provide additional information.
Type parameters:
#[command(name = "")]: set the command name (required).#[command(desc = "")]: set the command description.1#[command(default_permission = true)]: whether the command should be enabled by default.
Field parameters:
#[command(rename = "")]: use a different option name than the field name.#[command(desc = "")]: set the option description.1#[command(channel_types = "")]: restricts the channel choice to specific types.2
It is mandatory to provide a description for each option and the command itself,
either using documentation comments or desc attribute parameter.
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>,
}Documentation comments can also be used. Only the fist line will be taken in account. ↩
List
ChannelTypenames in snake_case separated by spaces likeguild_text private. ↩
Required methods
Create an ApplicationCommandData for this type.