Skip to content
Classgatewayv0.9.0

UserContextMenuHandler

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

Pass the command name(s) as the generic, the same as @UserContextMenuRoute. Read the right-clicked user from this.target and that same user's guild member from this.targetMember.

abstract class UserContextMenuHandler<
    Names extends NamesFor<ApplicationCommandType.User>,
    Cache extends CacheType = MenuCacheFor<ApplicationCommandType.User, Names>
> extends InteractionHandler<UserContextMenuCommandInteraction<Cache>>

Member visibility

Filter class members by access level.

dispatch

The bag for this dispatch. Each interaction gets its own. Every handler for one event shares a single bag.

protected readonly dispatch: DispatchContext

Inherited from:BaseHandler

event

protected readonly event: Event

Inherited from:BaseHandler

route

The selected context-menu command's name, without the interaction-kind prefix.

protected readonly route: Names

sender

The reply surface for this interaction. Pass the handler to reply from outside its class.

readonly sender: TSender

Inherited from:RepliableHandler

target

protected target: User

delete()

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

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

Inherited from:RepliableHandler

execute()

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

match()

Run the case for the selected command. Use this only when the handler is registered for several names.

Provide one case per registered name, keyed by the name Discord shows in the right-click menu. Each case receives the clicked user and that user's guild member, both narrowed to the cache state of that one command. The cases must cover every name in the generic. A missing name or an unknown key is a compile error.

protected async match<Ret, Cases>(
    cases: OnlyCases<Cases, UserMenuCases<Names, Ret>>
): Promise<MatchResult<Ret, Cases>>
Parameter: cases

One handler per registered command name.

Type parameter: Ret

The type that every case must return. Leave it out to get the union of what the cases return.