45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { ChatInputCommandInteraction, Collection, Events, SlashCommandBuilder } from "discord.js";
|
|
import * as notification from "./notification";
|
|
import * as blocklist from "./blocklist";
|
|
import * as info from "./info";
|
|
import * as preserveSettings from "./preserveSettings";
|
|
import client from "../client";
|
|
import getDefaultEmbed from "../tools/defaultEmbeds";
|
|
|
|
const commands = new Collection<string, { builder: SlashCommandBuilder, execute: (interaction: ChatInputCommandInteraction) => Promise<void> }>();
|
|
commands.set(notification.builder.name, notification);
|
|
commands.set(blocklist.builder.name, blocklist);
|
|
commands.set(info.builder.name, info);
|
|
commands.set(preserveSettings.builder.name, preserveSettings);
|
|
|
|
client.on(Events.InteractionCreate, async (interaction) => {
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
const command = commands.get(interaction.commandName);
|
|
|
|
if (!command) {
|
|
console.error(`No command matching ${interaction.commandName} was found`);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await command.execute(interaction);
|
|
} catch (e) {
|
|
|
|
if (e instanceof Error && "stack" in e) {
|
|
console.error(e.stack);
|
|
} else {
|
|
console.error(e)
|
|
}
|
|
|
|
|
|
const embed = getDefaultEmbed();
|
|
embed.setTitle("Something went wrong");
|
|
embed.setDescription("An unexpected error occurred while processing your command. Please contact support if the problem persists");
|
|
embed.setColor(0xD01B15);
|
|
await interaction.reply({
|
|
embeds: [embed],
|
|
ephemeral: true
|
|
}).catch();
|
|
}
|
|
}); |