SlashHandler
Base class for a chat-input (slash) command handler.
Pass the route from the generated registry as the generic, the same string as @SlashRoute, then read this.options for a single command or this.match for several. Command authoring stays plain discord.js, seedcord codegen reads its toJSON() to type these options.
abstract class SlashHandler<
Route extends keyof SlashRegistry,
Cache extends CacheType = CacheFor<Route>
> extends InteractionHandler<ChatInputCommandInteraction<Cache>>Member visibility
Filter class members by access level.
constructor
Constructs a new instance of the InteractionHandler class
InteractionHandler(
event: Repliable,
core: Core,
dispatch: DispatchContext
)Inherited from:InteractionHandler
Route
One or more route keys from SlashRegistry, e.g. 'ban' or 'ban' | 'kick'.
Route extends keyof SlashRegistryCache
The interaction cache state. The command's contexts set it.
Cache extends CacheType = CacheFor<Route>core
readonly core: TCoreInherited from:BaseHandler
dispatch
The bag for this dispatch. Each interaction gets its own. Every handler for one event shares a single bag.
protected readonly dispatch: DispatchContextInherited from:BaseHandler
event
protected readonly event: EventInherited from:BaseHandler
logger
protected readonly logger: LoggerInherited from:BaseHandler
The typed options for this command's route. Only the getters for kinds this command declares appear. Each getter's name argument is restricted to that command's options of its kind.
- A required option drops the null. - Choices narrow to their literal union. - A channel option declared with
addChannelTypesnarrows to those types.
Use this.event.options directly for anything outside this view, such as getSubcommand(). However, for the common case, the methods in this would suffice.
protected options: SlashOptions<Route, Cache>routeId
protected readonly routeId: stringInherited from:RepliableHandler
sender
The reply surface for this interaction. Pass the handler to reply from outside its class.
readonly sender: TSenderInherited from:RepliableHandler
buildSender()
protected buildSender(
event: Event,
core: Core,
dispatch: DispatchContext
): ReplySenderInherited from:RepliableHandler
defer()
Show a "thinking" placeholder, then fill it later with edit.
Inherited from:RepliableHandler
delete()
Delete the initial reply or deferred placeholder. Pass a target to delete a message a prior send returned.
Inherited from:RepliableHandler
edit()
Rewrite the initial reply or deferred placeholder. The targeted form rewrites a message a prior send returned.
protected async edit(
response: ReplyResponse<TNative> | string
): Promise<TMessage>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.
Inherited from:BaseHandler
followUp()
Send a new message once the interaction is acknowledged.
protected async followUp(
response: ReplyResponse<TNative> | string,
opts?: SendOpts
): Promise<TMessage>Inherited from:RepliableHandler
Run the arm for whichever command fired. Use this only when the handler is registered for several routes.
Provide one arm per registered route, keyed by its route string, and each arm receives that route's own narrowed options. The arms must cover every route in the generic, a missing route or an unknown key is a compile error.
protected async match<Ret>(
arms: SlashMatchArms<Route, Cache, Ret>
): Promise<Ret>armsOne handler per registered route, keyed by route string.
reply()
Send the initial response, exactly once.
protected async reply(
response: ReplyResponse<TNative> | string,
opts?: SendOpts
): Promise<TMessage>Inherited from:RepliableHandler
send()
Routes to reply, followUp, or edit based on the current ack state.
protected async send(
response: ReplyResponse<TNative> | string,
opts?: SendOpts
): Promise<TMessage>Inherited from:RepliableHandler
showModal()
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).
protected async showModal(
this: InteractionHandler<NonModalInteraction>,
modal: ModalLike
): Promise<void>Inherited from:InteractionHandler