Files
website/docs/guide/walkthrough/autocomplete.md
2023-07-29 11:09:03 -05:00

1.1 KiB

sidebar_position
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

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.