# ContextMenuHandler

`class` in `gateway` · v0.2.1

<https://docs.seedcord.org/packages/gateway/0.2.1/classes/context-menu-handler>

Base class for a context-menu command handler (right-click a user or a message).

Pass the kind from `discord.js`'s ApplicationCommandType as the generic, the same value as `@ContextMenuRoute`. Read the right-clicked entity from `this.target`, a `User` for a user menu and a `Message` for a message menu. Context menus carry no options, so a handler registered for several names reads `this.target` uniformly with no per-name branch.

```ts
abstract class ContextMenuHandler<
    Kind extends ContextMenuKind,
    Cache extends CacheType = "cached"
> extends InteractionHandler<InteractionFor<Kind, Cache>>
```

## Examples

```ts
\@ContextMenuRoute(ApplicationCommandType.Message, 'Report Message')
class ReportMessage extends ContextMenuHandler<ApplicationCommandType.Message> {
    async execute() {
        const message = this.target;
    }
}
```

## Constructors

### constructor

```ts
InteractionHandler(
    event: Repliable,
    core: Core,
    dispatch?: DispatchContext
)
```

Constructs a new instance of the `InteractionHandler` class

## Properties

### core

```ts
readonly core: TCore
```

### dispatch

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

### event

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

### logger

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

### routeId

```ts
protected readonly routeId: string
```

### sender

```ts
protected readonly sender: TSender
```

### target

```ts
protected target: TargetFor<Kind, Cache>
```

### targetMember

```ts
protected targetMember: TargetMemberFor<Kind, Cache>
```

The invoking guild member, resolved only on user menus. Reading it on a message menu is a compile error since the type is `never` there.

## Methods

### buildSender

```ts
protected buildSender(
    event: Event,
    core: Core,
    routeId: string
): ReplySender
```

### defer

```ts
protected async defer(opts?: DeferOpts): Promise<void>
```

Show a "thinking" placeholder, then fill it later with [`edit`](/packages/gateway/0.2.1/classes/slash-handler#edit).

### delete

```ts
protected async delete(target?: TMessage): Promise<void>
```

Delete the initial reply or deferred placeholder. Pass a target to delete a message a prior send returned.

### edit

```ts
protected async edit(
    response: ReplyResponse<TNative> | string
): Promise<TMessage>
```

```ts
protected async edit(
    target: TMessage,
    response: ReplyResponse<TNative> | string
): Promise<TMessage>
```

Rewrite the initial reply or deferred placeholder. The targeted form rewrites a message a prior send returned.

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

### followUp

```ts
protected async followUp(
    response: ReplyResponse<TNative> | string,
    opts?: SendOpts
): Promise<TMessage>
```

Send a new message once the interaction is acknowledged.

### reply

```ts
protected async reply(
    response: ReplyResponse<TNative> | string,
    opts?: SendOpts
): Promise<TMessage>
```

Send the initial response, exactly once.

### send

```ts
protected async send(
    response: ReplyResponse<TNative> | string,
    opts?: SendOpts
): Promise<TMessage>
```

Routes to reply, followUp, or edit based on the current ack state.

### showModal

```ts
protected async showModal(
    this: InteractionHandler<NonModalInteraction>,
    modal: ModalLike
): Promise<void>
```

Open a modal. Must be the initial response to this interaction. The modal kind rejects this call at compile time (Discord forbids a modal in response to a modal).
