Skip to content
V2 has arrived! A lot has changed, so treat this as a fresh start.

AutocompleteHelper

A utility class designed to manage and filter autocomplete choices for Discord application commands. It simplifies the process of providing suggestions based on user input.

ParameterTypeDescription
valueTThe current input value from the user to filter against.
user?APIUserThe user object, used to provide localized results if available.
  • Type: APIApplicationCommandOptionChoice<T>[]
  • Returns the current array of choices stored in the helper.

Adds one or more choices to the existing list.

  • Returns: this

Overwrites the current list of choices with a new set.

  • Returns: this

Removes all choices from the helper.

  • Returns: this

Filters the stored choices based on the value provided in the constructor.

  • Parameters:
    • filterFields?: (keyof APIApplicationCommandOptionChoice<T>)[] — Fields to include in the search (e.g., ['name', 'value']). If omitted, it filters by all available fields including localizations.
  • Returns: APIApplicationCommandOptionChoice<T>[] — The filtered list of choices.
const helper = new AutocompleteHelper<string>("apple").addChoices(
{ name: "Apple", value: "apple" },
{ name: "Banana", value: "banana" },
{ name: "Cherry", value: "cherry" },
{ name: "Something else", value: "applejuice" }
);
// Returns only the "Apple" choice because "applejuice" is a value and not a name
const results = helper.response(["name"]);