mirror of
https://github.com/sern-handler/website
synced 2026-06-11 02:12:25 +00:00
46 lines
1.1 KiB
Markdown
46 lines
1.1 KiB
Markdown
---
|
|
sidebar_position: 7
|
|
---
|
|
|
|
# Autocomplete
|
|
|
|
|
|
Autocomplete is a special interaction where it can happen on multiple options on a single command. We've handled this with a simple
|
|
tree search algorithm in a nested options tree.
|
|
|
|
## Example
|
|
|
|
```ts title="src/commands/cheese.ts" {11-18}
|
|
export default commandModule({
|
|
type: CommandType.Slash,
|
|
description: "show me cheese",
|
|
options: [
|
|
{
|
|
name: "list",
|
|
type: ApplicationCommandOptionType.String,
|
|
description: "pick a cheese to show",
|
|
required: true,
|
|
autocomplete: true,
|
|
command: {
|
|
onEvent: [],
|
|
execute: (ctx) => {
|
|
const focus = ctx.options.getFocused();
|
|
ctx.respond(['gouda', 'parmesan', 'harvati']
|
|
.map((cheese) => ({ name: cheese, value: cheese })));
|
|
}
|
|
}
|
|
}
|
|
],
|
|
execute: (ctx, [, args]) => {
|
|
const cheese = args.getString('list', true);
|
|
ctx.reply('selected cheese');
|
|
}
|
|
})
|
|
|
|
|
|
```
|
|
|
|
Sern will handle autocomplete interactions at arbitrary depths and subcommand levels.
|
|
|
|
|