Trait twilight_interactions::command::CreateOption
source · [−]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.
Attribute | Type | Location | Description |
---|---|---|---|
name | str | Variant | Set the name of the command option choice. |
name_localizations | fn 1 | Variant | Localized name of the command option choice. |
value | str , i64 or f64 | Variant | Value of the command option choice. |
Path to a function that returns a type that implement
IntoIterator<Item = (ToString, ToString)>
. See the module documentation to learn more. ↩
Required Methods
fn create_option(data: CreateOptionData) -> CommandOption
fn create_option(data: CreateOptionData) -> CommandOption
Create a CommandOption
from this type.