pub trait CreateOption: Sized {
    fn create_option(data: CreateOptionData) -> CommandOption;
}
Expand description

Create a command option from a type.

This trait is used by the implementation of CreateCommand generated by the derive macro. See the module documentation for a list of implemented types.

Option choices

This trait can be derived on enums to represent command options with predefined choices. The #[option] attribute must be present on each variant.

Example

use twilight_interactions::command::CreateOption;

#[derive(CreateOption)]
enum TimeUnit {
    #[option(name = "Minute", value = 60)]
    Minute,
    #[option(name = "Hour", value = 3600)]
    Hour,
    #[option(name = "Day", value = 86400)]
    Day
}

Macro attributes

The macro provide a #[option] attribute to configure the generated code.

AttributeTypeLocationDescription
namestrVariantSet the name of the command option choice.
name_localizationsfn1VariantLocalized name of the command option choice.
valuestr, i64 or f64VariantValue of the command option choice.

  1. Path to a function that returns a type that implement IntoIterator<Item = (ToString, ToString)>. See the module documentation to learn more. 

Required Methods

Create a CommandOption from this type.

Implementations on Foreign Types

Implementors