Autocomplete
function in meocord/decorator Since 4.0.0
Autocomplete<_R = unknown>(
commandPath: string,
optionName?: string,
): <P extends Record<string, any>, R>(
target: object,
propertyKey: string,
_descriptor:
| TypedPropertyDescriptor<
(interaction: AutocompleteInteraction, params: P) => R
>
| TypedPropertyDescriptor<(interaction: AutocompleteInteraction) => R>
| TypedPropertyDescriptor<() => R>,
) => voidSuggests values for an option of a chat input command as the user types.
Use it for an option with more possible values than a fixed list of choices holds, such as a search over
your own data. Enable it on the option with setAutocomplete(true) in the command's builder.
Where it runs
- The handler — after the guards, with no interceptors
Parameters
| Name | Type | Description |
|---|---|---|
commandPath | string | The command, such as |
optionName? | string | The option to complete. Leave it out to handle every option, branching on
|
Returns
Returns a method decorator.
<P extends Record<string, any>, R>(
target: object,
propertyKey: string,
_descriptor:
| TypedPropertyDescriptor<
(interaction: AutocompleteInteraction, params: P) => R
>
| TypedPropertyDescriptor<(interaction: AutocompleteInteraction) => R>
| TypedPropertyDescriptor<() => R>,
) => voidExamples
@Autocomplete('fruit', 'name')
async completeFruit(interaction: AutocompleteInteraction) {
const { value } = interaction.options.getFocused(true)
const names = ['apple', 'banana', 'cherry'].filter(name => name.startsWith(value))
await interaction.respond(names.map(name => ({ name, value: name })))
}