Class: abstract InteractionHandler<Options>
Extends
Piece<Options,"interaction-handlers">
Type parameters
| Type parameter | Value |
|---|---|
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`
Source
projects/framework/src/lib/structures/InteractionHandler.ts:16
Properties
interactionHandlerType
readonlyinteractionHandlerType:InteractionHandlerTypes
The type for this handler
Since
3.0.0
Source
projects/framework/src/lib/structures/InteractionHandler.ts:14
Methods
none()
none():
OptionNone
Returns
OptionNone
Source
projects/framework/src/lib/structures/InteractionHandler.ts:77
parse()
parse(
_interaction:Interaction):Awaitable<Option<unknown>>
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>>
An Option (or a Promise 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();
}
Source
projects/framework/src/lib/structures/InteractionHandler.ts:67
run()
abstractrun(interaction:Interaction,parsedData?:unknown):unknown
Parameters
| Parameter | Type |
|---|---|
interaction | Interaction |
parsedData? | unknown |
Returns
unknown
Source
projects/framework/src/lib/structures/InteractionHandler.ts:22
some()
some()
some():
Some<never>
Returns
Some<never>
Source
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>
Source
projects/framework/src/lib/structures/InteractionHandler.ts:72
toJSON()
toJSON():
InteractionHandlerJSON
Returns
Overrides
Piece.toJSON
Source
projects/framework/src/lib/structures/InteractionHandler.ts:81