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.

AttributeTypeLocationDescription
namestrTypeName of the command (required).
descstrType / Field / VariantSet the subcommand name (required).
default_permissionboolTypeWhether the command should be enabled by default.
renamestrFieldUse a different option name than the field name.
autocompleteboolFieldEnable autocomplete on this field.
channel_typesstrFieldRestricts the channel choice to specific types.1
max_value, min_valuei64 or f64FieldSet 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>,
}

  1. List ChannelType names in snake_case separated by spaces like guild_text private

Associated Constants

Name of the command.

Required methods

Implementors