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 read the selected command's path from 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.
AutocompleteHandler(
event: AutocompleteInteraction<Cache>,
core: Core,
dispatch: DispatchContext,
responder: AutocompleteResponder<ApplicationCommandOptionChoiceData>
)Route
One or more route keys from SlashRegistry, e.g. 'search' or 'search' | 'find'.
Route extends keyof SlashRegistryCache
The interaction cache state. The command's contexts set it.
Cache extends CacheType = CacheFor<Route>core
readonly core: TCoreInherited from:BaseHandler
dispatch
The bag for this dispatch. Each interaction gets its own. Every handler for one event shares a single bag.
protected readonly dispatch: DispatchContextInherited from:BaseHandler
event
protected readonly event: EventInherited from:BaseHandler
protected focused: FocusedField<Route>logger
protected readonly logger: LoggerInherited from:BaseHandler
protected options: AutocompleteOptions<Route>protected readonly route: Routeprotected user: Userexecute()
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
getEvent(): ValidEventInherited from:BaseHandler
Run the case 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 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>>casesOne handler per autocompletable field, keyed by field name.
RetThe 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.
Send autocomplete suggestions, callback type 8. Prefer match, which restricts each field's choices to its declared type.
protected async respond(
choices: readonly ApplicationCommandOptionChoiceData[]
): Promise<void>