Skip to content
Classhttpv0.12.0

AutocompleteHandler

Base class for an autocomplete handler on the HTTP transport.

Pass the command route(s) from the generated registry as the generic. Branch on the focused field with this.match, read already-entered sibling options with this.options, and read the selected command's path from this.route.

abstract class AutocompleteHandler<
    Route extends keyof SlashRegistry
> extends BaseHandler<APIApplicationCommandAutocompleteInteraction, Core>

Member visibility

Filter class members by access level.

Showing members with Protected visibility and higher.

api

Typed Discord REST API (@discordjs/core/http-only) over core.rest, one instance per core.

protected api: API

dispatch

The bag for this dispatch. Each interaction gets its own. Every handler for one event shares a single bag.

protected readonly dispatch: DispatchContext

Inherited from:BaseHandler

event

protected readonly event: Event

Inherited from:BaseHandler

focused

The focused option for this interaction. value is always the raw partial string the user is typing, even for an integer or number option, so coerce it yourself when you need a number.

protected focused: FocusedField<Route>

options

The already-entered options on this command, restricted to the kinds Discord resolves during autocomplete (string, integer, number, boolean) with every read nullable, since a sibling is partial while the user types the focused field. The focused field is on this.focused.

protected options: AutocompleteOptions<Route>

route

The selected command's path, such as search/docs, without the interaction-kind prefix.

protected readonly route: Route

user

The user who sent this interaction, read from member.user in a guild and user in a DM.

protected user: APIUser

execute()

Holds the main logic of your handler. The dispatcher calls it after the handler's gates pass, so a gate that refuses stops execute() from running.

abstract execute(): Promisable<void>

Inherited from:BaseHandler

match()

Run the case for the focused field. An autocomplete always dispatches by which field is focused. Match is how you read it.

Provide one case per autocompletable field across the registered commands, keyed by field name. Each case receives the focused partial value and a respond typed to that field's choice value. The cases must cover every autocompletable field. A missing field or an unknown key is a compile error.

protected async match<Ret, Cases>(
    cases: OnlyCases<Cases, FocusedCases<Route, Ret>>
): Promise<MatchResult<Ret, Cases>>
Parameter: cases

One handler per autocompletable field, keyed by field name.

Type parameter: Ret

The type that every case must return. Leave it out to get the union of what the cases return.

Throws:

A SeedcordTypeError with MatchCaseMissing when the focused field doesn't have a case. Only a stale-deployed command can send one.