Skip to main content

Message Components

Setting the InteractionHandlerTypes option MessageComponent will have this InteractionHandler trigger for both SelectMenus and Buttons.

Here's a simple example:

const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework');

class MessageComponentHandler extends InteractionHandler {
constructor(ctx, options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.MessageComponent
});
}

parse(interaction) {
if (interaction.customId !== 'my-echo-button-or-select') return this.none();

return this.some();
}

async run(interaction) {
if (interaction.isButton()) {
await interaction.reply({
content: `You clicked a button`
});
} else {
await interaction.reply({
// Remember how we can have multiple values? Let's get the first one!
content: `You selected: ${interaction.values[0]}`
});
}
}
}
module.exports = {
MessageComponentHandler
};