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

22 lines
758 B
TypeScript
Raw Normal View History

2023-06-25 02:32:56 +00:00
import { ButtonInteraction, CacheType } from 'discord.js';
2023-06-28 18:45:14 +00:00
import { CYCLIC_API } from '../../../constants/cyclic.js';
2023-06-27 01:46:08 +00:00
import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js';
2023-06-25 02:32:56 +00:00
import { commands } from '../index.js';
export default async function handleButton(
interaction: ButtonInteraction<CacheType>,
) {
2023-06-28 18:45:14 +00:00
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
const commandName = url.pathname.split('/')[1];
2023-06-25 02:32:56 +00:00
const button = commands[commandName]?.button;
if (!button) {
console.error(`Button handler not found for "${commandName}"`);
return;
}
await interaction.deferUpdate();
await interaction.message.edit(
await normalizeInteractionReturnable(button(interaction)),
);
}