# ContextMenuHandler

`class` in `gateway` · v0.1.0-next.3

<https://docs.seedcord.org/packages/gateway/0.1.0-next.3/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

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

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