# AutocompleteHandler

`class` in `http` · v0.6.0

<https://docs.seedcord.org/packages/http/0.6.0/classes/autocomplete-handler>

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 find which command fired with `this.route`.

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

## Constructors

### constructor

```ts
AutocompleteHandler(
    event: APIApplicationCommandAutocompleteInteraction,
    core: Core,
    dispatch?: DispatchContext
)
```

Constructs a new instance of the `AutocompleteHandler` class

## Properties

### api

```ts
protected api: API
```

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

### core

```ts
readonly core: TCore
```

### dispatch

```ts
protected readonly dispatch: DispatchContext | undefined
```

### event

```ts
protected readonly event: Event
```

### focused

```ts
protected focused: FocusedField<Route>
```

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.

### logger

```ts
protected readonly logger: Logger
```

### options

```ts
protected options: AutocompleteOptions<Route>
```

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`.

### route

```ts
protected route: Route
```

The firing command route, for a field whose completion differs per registered command.

## Methods

### execute

```ts
abstract async execute(): Promise<void>
```

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.

### match

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

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

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.

### respond

```ts
protected async respond(
    choices: readonly APIApplicationCommandOptionChoice[]
): Promise<void>
```

Send autocomplete suggestions, callback type 8. Prefer [`match`](/packages/http/0.6.0/classes/autocomplete-handler#match), which restricts each field's choices to its declared type.
