Files
blitzkit/packages/bot/src/events/interactionCreate/handlers/button.tsx
T

27 lines
882 B
TypeScript
Raw Normal View History

2026-02-18 16:36:12 -06:00
import { ButtonInteraction, CacheType } from "discord.js";
import { commands } from "..";
import { normalizeInteractionReturnable } from "../../../core/discord/normalizeInteractionReturnable";
2023-06-25 02:32:56 +00:00
2024-09-08 10:11:24 -05:00
export async function handleButton(interaction: ButtonInteraction<CacheType>) {
2023-06-30 17:38:44 +00:00
await interaction.deferUpdate();
2023-10-11 18:26:35 -05:00
const url = new URL(`https://example.com/${interaction.customId}`);
2026-02-18 16:36:12 -06:00
const commandName = url.pathname.split("/")[1];
const button = commands[commandName]?.button;
2023-06-25 02:32:56 +00:00
if (!button) {
2023-10-17 20:58:36 -05:00
throw new Error(`Button handler not found for "${commandName}"`);
2023-06-30 17:38:44 +00:00
}
if (interaction.message.interaction?.user.id !== interaction.user.id) {
interaction.followUp({
ephemeral: true,
2026-02-18 16:36:12 -06:00
content: "You are not the author of this command.",
2023-06-30 17:38:44 +00:00
});
2023-06-25 02:32:56 +00:00
return;
}
await interaction.message.edit(
await normalizeInteractionReturnable(button(interaction)),
);
}