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
}
}
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
}
}