© 2026 Hedgehog Software, LLC
import { InteractionHandler, InteractionHandlerTypes, } from "@sapphire/framework"; import type { ButtonInteraction } from "discord.js"; import { client } from "../index.js"; export class ButtonHandler extends InteractionHandler { public constructor( ctx: InteractionHandler.LoaderContext, options: InteractionHandler.Options ) { super(ctx, { ...options, interactionHandlerType: InteractionHandlerTypes.Button, }); } public override async parse(interaction: ButtonInteraction) { const buttonId = interaction.customId; const [toDo, guildId, panelId, ticketModelId] = buttonId.split("-"); await interaction.deferReply({ ephemeral: true }); const guildData = await client.tickets.getGuild(guildId); if (!guildData) { { interaction.editReply({ content: i18next.t("commands:error.unknown", { warnEmoji: client.makeEmoji(EMOJI.WARNING), }), }); return this.none(); } } switch (toDo) { case "ticketCreate": { const ticketModel = guildData.ticketModels.find( (ticketModel) => ticketModel.ticketModelId === parseInt(ticketModelId) && ticketModel.panelId === parseInt(panelId) ); return this.some({ guildData, ticketModel }); } default: { return this.none(); } } } public async run( interaction: ButtonInteraction, data: { guildData: Prisma.GuildGetPayload<{ include: { panels: true; ticketModels: true; tickets: true; }; }>; ticketModel: TicketModel; } ) { //redacted to save space } }
interaction-handlers
Join the Discord to ask follow-up questions and connect with the community
Sapphire is a next-gen object-oriented Discord.js bot framework.
2,286 Members