# DispatchContext

`class` in `core` · v0.12.0

<https://seedcord.org/docs/packages/core/0.12.0/classes/dispatch-context>

State shared by middleware, gates, and handlers during one dispatch.

```ts
class DispatchContext<
    Kind extends DispatchKind = DispatchKind
> implements DispatchBag
```

## Constructors

### constructor

```ts
DispatchContext(
    kind: Kind,
    route: string,
    fallback?: boolean
)
```

Constructs a new instance of the `DispatchContext` class

## Properties

### declaredRoute

```ts
public get declaredRoute(): string | null
```

The [`routeId`](/docs/packages/core/0.12.0/classes/dispatch-context#route-id) of the handler's own route. It's `null` on an event and on the unhandled default.

### fallback

```ts
public readonly fallback: boolean
```

True when this route doesn't have a registered handler.

### id

```ts
public readonly id: `${string}-${string}-${string}-${string}-${string}`
```

### kind

```ts
public readonly kind: Kind
```

What started this dispatch, an interaction kind or `event`.

### route

```ts
public readonly route: string
```

The slash path, context menu name, custom-ID prefix, or event name that started this dispatch.
For a custom ID that seedcord didn't make, it can be empty or a cut-off piece of that ID.

### routeId

```ts
public get routeId(): string
```

The dispatch identifier, such as `slash:search/docs`, `button:approve`, or `event:messageCreate`.
Component identifiers contain the custom-ID prefix without encoded params.

## Methods

### get

```ts
public get<Key>(key: Key): DispatchState[Key] | undefined
```

### require

```ts
public require<Key>(
    key: Key
): Exclude<DispatchState[Key], undefined>
```

Read a key that must be present, with `undefined` stripped from the result.

### set

```ts
public set<Key>(key: Key, value: DispatchState[Key]): void
```
