first commit

This commit is contained in:
Space-Banane
2026-02-22 14:55:10 +01:00
commit 9235748a47
23 changed files with 2343 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { Client, Events, REST, Routes } from "discord.js";
import { getAllCommands, getCommand } from "../lib/commandRegistry";
import { GUILD_ID } from "../config";
export default async function (client: Client) {
const token = process.env.DISCORD_TOKEN!;
const clientId = client.user!.id; // use the ready client's ID
const rest = new REST().setToken(token);
const commandData = getAllCommands().map((cmd) => cmd.data.toJSON());
await rest.put(Routes.applicationGuildCommands(clientId, GUILD_ID), {
body: commandData,
});
console.log(`Registered ${commandData.length} slash command(s).`);
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = getCommand(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (err) {
console.error(err);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: "An error occurred.", ephemeral: true });
} else {
await interaction.reply({ content: "An error occurred.", ephemeral: true });
}
}
});
}