Skip to main content
Version: Next

ButtonKit

ButtonKit

A builder for creating buttons with additional features like interaction collectors and event handling.

Signature
class ButtonKit extends ButtonBuilder {
onClick(handler: CommandKitButtonBuilderInteractionCollectorDispatch, data?: CommandKitButtonBuilderInteractionCollectorDispatchContextData) => this;
onEnd(handler: CommandKitButtonBuilderOnEnd) => this;
onError(handler: EventInterceptorErrorHandler) => this;
filter(predicate: ButtonKitPredicate) => this;
dispose() => ;
}
  • Extends: ButtonBuilder

onClick

Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used. If unused, this expires after 24 hours or custom time if specified.

Example

const button = new ButtonKit()
.setLabel('Click me')
.setStyle(ButtonStyle.Primary)
.setCustomId('click_me')
.filter((interaction) => interaction.user.id === '1234567890')
.onClick(async (interaction) => {
await interaction.reply('You clicked me!');
});

const row = new ActionRowBuilder().addComponents(button);

const message = await channel.send({ content: 'Click the button', components: [row] });

// Remove onClick handler and destroy the interaction collector
button.onClick(null);

onEnd

method
(handler: CommandKitButtonBuilderOnEnd) => this

onError

method
(handler: EventInterceptorErrorHandler) => this

Sets the handler to run when the interaction collector ends.

filter

method
(predicate: ButtonKitPredicate) => this

Sets a filter for the interaction collector.

dispose

method
() =>

Disposes of the button collector and cleans up resources.