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

32 lines
1022 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-30 17:38:44 +00:00
import throwError from '../../../core/node/throwError.js';
2023-06-25 02:32:56 +00:00
import { commands } from '../index.js';
export default async function handleButton(
interaction: ButtonInteraction<CacheType>,
) {
2023-06-30 17:38:44 +00:00
await interaction.deferUpdate();
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) {
2023-06-30 17:38:44 +00:00
throwError(`Button handler not found for "${commandName}"`);
return;
}
if (interaction.message.interaction?.user.id !== interaction.user.id) {
interaction.followUp({
ephemeral: true,
content: 'You are not the author of this command.',
});
2023-06-25 02:32:56 +00:00
return;
}
await interaction.message.edit(
await normalizeInteractionReturnable(button(interaction)),
);
}