#[derive(ChoiceParameter)]
{
// Attributes available to this derive:
#[name]
#[name_localized]
}
Expand description
Use this derive macro on an enum to easily generate a choice parameter type. A choice parameter is mainly useful in slash commands. It allows you to constrain input to a fixed set of choices.
#[derive(poise::ChoiceParameter)]
pub enum MyChoice {
#[name = "The first choice"]
ChoiceA,
// A choice can have multiple names
#[name = "The second choice"]
#[name = "ChoiceB"]
ChoiceB,
// Or no name, in which case it falls back to the variant name "ChoiceC"
ChoiceC,
}
Example invocations:
~yourcommand "The first choice"
- without the quotes, each word would count as a separate argument~yourcommand ChoiceB
~yourcommand cHoIcEb
- names are case-insensitive
§Localization
In slash commands, you can take advantage of Discord’s localization.
#[derive(poise::ChoiceParameter)]
pub enum Food {
#[name_localized("de", "Eier")]
#[name_localized("es-ES", "Huevos")]
Eggs,
#[name_localized("de", "Pizza")]
#[name_localized("es-ES", "Pizza")]
Pizza,
#[name_localized("de", "Müsli")]
#[name_localized("es-ES", "Muesli")]
Cereals,
}
When invoking your slash command, users will be shown the name matching their locale.
You can also set localized choice names programmatically; see CommandParameter::choices