2023-06-25 02:32:56 +00:00
|
|
|
import { ButtonInteraction, CacheType } from 'discord.js';
|
2023-07-11 19:54:57 +00:00
|
|
|
import { commands } from '..';
|
2024-09-08 10:15:42 -05:00
|
|
|
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}`);
|
2023-06-28 18:45:14 +00:00
|
|
|
const commandName = url.pathname.split('/')[1];
|
2023-08-04 18:24:20 +00:00
|
|
|
const button = (await 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,
|
|
|
|
|
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)),
|
|
|
|
|
);
|
|
|
|
|
}
|