-
Notifications
You must be signed in to change notification settings - Fork 0
Autocomplete
The autocomplete functionality is offered by Discord and allows you to create interactive lists that you can search against for string and number slash command options.
To do this, we shall use the @On.Autocomplete
decorator, that optionally takes an optionName
and subcommand
. If you do not pass any parameters to the decorator, it will catch ALL autocompletions for the command, if you offer an option name, it will match the option name against what you supplied and only work for that one, lastly if you add an option name AND a subcommand, it will only listen to events from an autocomplete interaction that matches both option name and subcommand.
To use auto complete, in a Command
class you can do the following method:
@On.Autocomplete()
public async onAutocomplete(context: Context): Promise<void> {
const interaction = context.getInteraction<AutocompleteInteraction>();
const query = interaction.options.getFocused() as string;
// Do filtering here, and return an array of options (Type: `{ name: string, value: string }[]`), example:
await interaction.respond([
{ name: 'Hello', value: 'hello' },
{ name: 'Goodbye', value: 'goodbye' },
]);
}
Additionally if I have a subcommand called "books" and an option called "name", I can do:
@On.Autocomplete('name', 'books')
Home | Turbo Engine | GitHub | NPM
- Configuration
- Creating Commands
- Adding Autocomplete
- Adding Context Menu
- Middleware Setup
- Built-In Helpers
- Promise Queue
- Command Sessions
- Setting Up OAuth
- Turbo Engine Github
- Need your own plugin? Contact Me
- Have an idea? Let's Discuss
- Want to support me? Buy me a coffee