mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-10 11:16:10 +01:00
28 lines
890 B
TypeScript
28 lines
890 B
TypeScript
import { ButtonInteraction, CacheType } from 'discord.js';
|
|
import { commands } from '..';
|
|
import { normalizeInteractionReturnable } from '../../../core/discord/normalizeInteractionReturnable';
|
|
|
|
export async function handleButton(interaction: ButtonInteraction<CacheType>) {
|
|
await interaction.deferUpdate();
|
|
|
|
const url = new URL(`https://example.com/${interaction.customId}`);
|
|
const commandName = url.pathname.split('/')[1];
|
|
const button = (await commands)[commandName]?.button;
|
|
|
|
if (!button) {
|
|
throw new Error(`Button handler not found for "${commandName}"`);
|
|
}
|
|
|
|
if (interaction.message.interaction?.user.id !== interaction.user.id) {
|
|
interaction.followUp({
|
|
ephemeral: true,
|
|
content: 'You are not the author of this command.',
|
|
});
|
|
return;
|
|
}
|
|
|
|
await interaction.message.edit(
|
|
await normalizeInteractionReturnable(button(interaction)),
|
|
);
|
|
}
|