Discord.https - v3.0.16
    Preparing search index...

    Builder utility for creating autocomplete keys used by the router’s autocomplete() method.

    This class helps you construct a colon-delimited key that uniquely identifies the path to an option with autocomplete enabled in a slash command, including subcommands and subcommand groups.

    Simply, This class is used to manage and resolve the paths for autocomplete keys in Discord application commands.

    const weather = router.command(
    (builder) =>
    builder
    .setName("weather")
    .setDescription("Query weather information!")
    .addStringOption(option =>
    option
    .setName("city")
    .setDescription("City to get the weather for")
    .setAutocomplete(true) // Enable autocomplete for this option
    ),
    handler
    );
    router.autocomplete(weather.getAutoCompleteKey("city"), autocompleteMiddleware);
    Index

    Methods

    • Clones the current AutoCompleteKeyBuilder. Throws an error if the path has already been partially built.

      Returns AutoCompleteKeyBuilder

      const weatherCommandAutoCompleteKey = router.command(
      (builder) =>
      builder
      .setName("weather")
      .setDescription("Query weather information!")
      // First autocomplete option
      .addStringOption((option) =>
      option
      .setName("city")
      .setDescription("City to get the weather for")
      .setAutocomplete(true)
      )
      //Second autocomplete option
      .addStringOption((option) =>
      option
      .setName("unit")
      .setDescription("Unit for temperature")
      .setAutocomplete(true)
      ),
      (interaction) => handler

      const cityAutoCompleteKey = weatherCommandAutoCompleteKey.clone();
      const unitAutoCompleteKey = weatherCommandAutoCompleteKey.clone();

      router.autocomplete(cityAutoCompleteKey.getAutoCompleteKey("city"), autocompleteMiddleware);
      router.autocomplete(unitAutoCompleteKey.getAutoCompleteKey("unit"), autocompleteMiddleware2);
    • Get an autocomplete key for router.

      Parameters

      • name: string

        The option name.

      Returns AutoCompleteKeyBuilder

      This builder instance for chaining.

      const weatherCommandAutoCompleteKey = router.command(
      (builder) =>
      builder
      .setName("weather")
      .setDescription("Query weather information!")
      .addStringOption((option) =>
      option
      .setName("city")
      .setDescription("City to get the weather for")
      .setAutocomplete(true)
      )

      router.autocomplete(weatherCommandAutoCompleteKey.getAutocompleteKey("city"), autocompleteMiddleware);
    • Get a subcommand for an autocomplete key from a slash command.

      Parameters

      • name: string

        Subcommand name.

      Returns AutoCompleteKeyBuilder

      This builder instance for chaining.

      const musicCommand = router.command(
      (builder) =>
      builder
      .setName("music")
      .setDescription("Music related commands")
      .addSubcommand((sub) =>
      sub
      .setName("play")
      .setDescription("Play a song")
      .addStringOption((option) =>
      option
      .setName("song")
      .setDescription("Song name")
      .setAutocomplete(true)
      )
      ), commandMiddleware);

      const MusicCommandAutoCompleteKey = musicCommand.getSubCommand("play").getAutocompleteKey("song");

      router.autocomplete(MusicCommandAutoCompleteKey, handler)
    • Get a subcommandgroup for an autocomplete key from a slash command.

      Parameters

      • name: string

      Returns AutoCompleteKeyBuilder

      const adminCommand = router.command(
      (builder) =>
      builder
      .setName("admin")
      .setDescription("Admin utilities")
      .addSubcommandGroup((group) =>
      group
      .setName("user")
      .setDescription("User-related commands")
      .addSubcommand((sub) =>
      sub
      .setName("ban")
      .setDescription("Ban a user")
      .addStringOption((option) =>
      option
      .setName("reason")
      .setDescription("Reason for banning")
      .setAutocomplete(true)
      )
      )
      ),
      commandHandler
      );

      router.autocomplete(
      adminCommand
      .getSubCommandGroup("user")
      .getSubCommand("ban")
      .getAutocompleteKey("reason"), AutoCompleteHandler
      );