Skip to main content

Abstract Class: InteractionHandler<Options>

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:6

Extends​

  • Piece<Options, "interaction-handlers">

Type Parameters​

Type ParameterDefault type
Options extends OptionsOptions

Constructors​

Constructor​

new InteractionHandler<Options>(context: LoaderContext, options: Options): InteractionHandler<Options>

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:16

Parameters​

ParameterType
contextLoaderContext
optionsOptions

Returns​

InteractionHandler<Options>

Overrides​

Piece< Options, 'interaction-handlers' >.constructor

Properties​

interactionHandlerType​

readonly interactionHandlerType: InteractionHandlerTypes

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:14

The type for this handler

Since​

3.0.0

Methods​

none()​

none(): None

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:77

Returns​

None


parse()​

parse(_interaction: Interaction): Awaitable<Option<unknown, boolean>>

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:67

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​

ParameterType
_interactionInteraction

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();
}

run()​

abstract run(interaction: Interaction, parsedData?: unknown): unknown

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:22

Parameters​

ParameterType
interactionInteraction
parsedData?unknown

Returns​

unknown


some()​

Call Signature​

some(): Some<never>

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:71

Returns​

Some<never>

Call Signature​

some<T>(data: T): Some<T>

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:72

Type Parameters​
Type Parameter
T
Parameters​
ParameterType
dataT
Returns​

Some<T>


toJSON()​

toJSON(): InteractionHandlerJSON

Defined in: projects/framework/src/lib/structures/InteractionHandler.ts:81

Defines the JSON.stringify behavior of this piece.

Returns​

InteractionHandlerJSON

Overrides​

Piece.toJSON