Skip to content
Classgatewayv0.7.5

AutocompleteHandler

Base class for a Discord autocomplete handler.

Pass the command route(s) from the generated registry as the generic, the same string(s) as @AutocompleteRoute. Branch on the focused field with this.match, read already-entered sibling options with this.options, and find which command fired with this.route.

abstract class AutocompleteHandler<
    Route extends keyof SlashRegistry,
    Cache extends CacheType = CacheFor<Route>
> extends BaseHandler<AutocompleteInteraction<Cache>>

Member visibility

Filter class members by access level.

Showing members with Protected visibility and higher.

Cache

The interaction cache state. The command's contexts set it.

Cache extends CacheType = CacheFor<Route>

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 firing command route, for a field whose completion differs per registered command.

protected route: Route

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(): Promise<void>

Inherited from:BaseHandler

getEvent()

getEvent(): ValidEvent

Inherited from:BaseHandler

match()

Run the arm for the focused field. Because an autocomplete always dispatches by which field is focused, match is how you read it. There is no single-field shortcut the way slash/component handlers have one.

Provide one arm per autocompletable field across the registered commands, keyed by field name. Each arm receives the focused partial value and a respond typed to that field's choice value. The arms must cover every autocompletable field, a missing field or an unknown key is a compile error. A focused field with no arm, only reachable from a stale-deployed command, throws at runtime.

protected async match<Ret>(
    arms: FocusedArms<Route, Ret>
): Promise<Ret>
Parameter: arms

One handler per autocompletable field, keyed by field name.