Skip to content

CIRCE / DOCUMENTATION

Autocomplete

Answer autocomplete options of a slash command.

Documentation menu
On this page

Set autocomplete on a command and mark the option with setAutocomplete(true).

type AutocompleteHandler = (ctx: AutocompleteContext) => void | Promise<void>;
export default defineCommand({
  builder: new SlashCommandBuilder()
    .setName("tag")
    .setDescription("Show a tag")
    .addStringOption((o) => o.setName("name").setDescription("Tag").setAutocomplete(true)),
  async autocomplete({ interaction }) {
    const focused = interaction.options.getFocused();
    await interaction.respond(
      ["rules", "faq", "roles"].filter((n) => n.startsWith(focused)).map((n) => ({ name: n, value: n })),
    );
  },
  async execute({ interaction }) { /* … */ },
});

Behavior

  • Discord requires a response within 3 seconds and accepts only a choice list.
  • If the handler throws, Circe responds with an empty list and reports the error through onError with the autocomplete kind.
  • Fields: see autocomplete context.
  • Guards do not run on autocomplete.