Skip to main content

autocomplete

Attribute Macro autocomplete 

Source
#[autocomplete]
Expand description

Defines an Autocomplete Handler from a function taking an optional leading ctx: Ctx and what the user has typed so far as input: &str. Attach it to a string, integer, or number Option with #[option("...", autocomplete = name)].

ⓘ
#[autocomplete]
fn fruits(input: &str) -> Vec<&'static str> {
    FRUITS.iter().copied().filter(|f| f.starts_with(input)).collect()
}

/// Pick a fruit
#[command]
fn fruit(#[option("Fruit", autocomplete = fruits)] name: &str) -> String { ... }

Return a Vec of strings, numbers, (name, value) pairs, or ApplicationCommandOptionChoices (at most 25 are sent), or a Result of one.