Class: abstract InteractionHandler<Options>
Extends
Piece<Options,"interaction-handlers">
Type Parameters
| Type Parameter | Default type |
|---|---|
Options extends Options | Options |
Constructors
new InteractionHandler()
new InteractionHandler<
Options>(context:LoaderContext,options:Options):InteractionHandler<Options>
Parameters
| Parameter | Type |
|---|---|
context | LoaderContext |
options | Options |
Returns
InteractionHandler<Options>
Overrides
`Piece< Options, 'interaction-handlers'
.constructor`
Defined in
projects/framework/src/lib/structures/InteractionHandler.ts:16
Properties
interactionHandlerType
readonlyinteractionHandlerType:InteractionHandlerTypes
The type for this handler
Since
3.0.0
Defined in
projects/framework/src/lib/structures/InteractionHandler.ts:14
Methods
none()
none():
None<any>
Returns
None<any>
Defined in
projects/framework/src/lib/structures/InteractionHandler.ts:77
parse()
parse(
_interaction:Interaction):Awaitable<Option<unknown,boolean>>
A custom function that will be called when checking if an interaction should be passed to this handler. You can use this method to not only filter by ids, but also pre-parse the data from the id for use in the run method.
By default, all interactions of the type you specified will run in a handler. You should override this method to change that behavior.
Parameters
| Parameter | Type |
|---|---|
_interaction | Interaction |
Returns
Awaitable<Option<unknown, boolean>>
An Option (or a Promised Option) that indicates if this interaction should be handled by this handler, and any extra data that should be passed to the run method
Examples
// Parsing a button handler
public override parse(interaction: ButtonInteraction) {
if (interaction.customId.startsWith('my-awesome-clicky-button')) {
// Returning a `some` here means that the run method should be called next!
return this.some({ isMyBotAwesome: true, awesomenessLevel: 9001 });
}
// Returning a `none` means this interaction shouldn't run in this handler
return this.none();
}
// Getting data from a database based on the custom id
public override async parse(interaction: ButtonInteraction) {
// This code is purely for demonstration purposes only!
if (interaction.customId.startsWith('example-data')) {
const [, userId, channelId] = interaction.customId.split('.');
const dataFromDatabase = await container.prisma.exampleData.findFirst({ where: { userId, channelId } });
// Returning a `some` here means that the run method should be called next!
return this.some(dataFromDatabase);
}
// Returning a `none` means this interaction shouldn't run in this handler
return this.none();
}
Defined in
projects/framework/src/lib/structures/InteractionHandler.ts:67
run()
abstractrun(interaction:Interaction,parsedData?:unknown):unknown
Parameters
| Parameter | Type |
|---|---|
interaction | Interaction |
parsedData? | unknown |
Returns
unknown
Defined in
projects/framework/src/lib/structures/InteractionHandler.ts:22
some()
some()
some():
Some<never>
Returns
Some<never>
Defined in
projects/framework/src/lib/structures/InteractionHandler.ts:71
some(data)
some<
T>(data:T):Some<T>
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
data | T |
Returns
Some<T>
Defined in
projects/framework/src/lib/structures/InteractionHandler.ts:72
toJSON()
toJSON():
InteractionHandlerJSON
Defines the JSON.stringify behavior of this piece.
Returns
Overrides
Piece.toJSON
Defined in
projects/framework/src/lib/structures/InteractionHandler.ts:81