Files
blitzkit/src/events/interactionCreate/handlers/chatInputCommand.ts
T

56 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-06-25 02:32:56 +00:00
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
CacheType,
ChatInputCommandInteraction,
} from 'discord.js';
2023-06-27 01:46:08 +00:00
import negativeEmbed from '../../../core/discord/negativeEmbed.js';
import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js';
import warningEmbed from '../../../core/discord/warningEmbed.js';
2023-06-27 01:43:30 +00:00
import { psa } from '../../../core/node/psa.js';
2023-06-25 02:32:56 +00:00
import { handleError } from '../../error.js';
import { commands } from '../index.js';
export default async function handleChatInputCommand(
interaction: ChatInputCommandInteraction<CacheType>,
) {
2023-06-27 01:43:30 +00:00
const registry = commands[interaction.commandName];
2023-06-25 02:32:56 +00:00
console.log(interaction.toString());
await interaction.deferReply();
try {
2023-06-27 01:43:30 +00:00
const returnable = await registry.handler(interaction);
2023-06-25 02:32:56 +00:00
2023-06-27 01:43:30 +00:00
if (registry.handlesInteraction) return;
2023-06-25 02:32:56 +00:00
2023-06-27 02:02:00 +00:00
const reply = await normalizeInteractionReturnable(returnable!);
2023-06-25 02:32:56 +00:00
if (psa.data) {
if (!reply.embeds) reply.embeds = [];
reply.embeds.push(warningEmbed(psa.data.title, psa.data.description));
}
await interaction.editReply(reply);
} catch (error) {
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setLabel('Get Help on Discord Server')
.setURL('https://discord.gg/nDt7AjGJQH')
.setStyle(ButtonStyle.Link),
);
await interaction.editReply({
embeds: [
negativeEmbed(
(error as Error).message,
`${(error as Error).cause ?? 'No further information is available.'}`,
),
],
components: [actionRow],
});
handleError(error as Error, interaction.commandName);
}
}