25 lines
690 B
TypeScript
25 lines
690 B
TypeScript
import { REST, Routes } from "discord.js";
|
|
import type { Command } from "./command";
|
|
|
|
export const registerCommands = async (
|
|
commands: Command[],
|
|
clientId: string
|
|
) => {
|
|
const DISCORD_TOKEN = Bun.env.DISCORD_TOKEN;
|
|
if (!DISCORD_TOKEN) {
|
|
console.error("No DISCORD_TOKEN found in environment variables.");
|
|
return;
|
|
}
|
|
|
|
const rest = new REST({ version: "10" }).setToken(DISCORD_TOKEN);
|
|
|
|
try {
|
|
await rest.put(Routes.applicationCommands(clientId), {
|
|
body: commands.map((command) => command.data.toJSON()),
|
|
});
|
|
console.log(`Registered ${commands.length} commands.`);
|
|
} catch (error) {
|
|
console.error("Error while registering commands:", error);
|
|
}
|
|
};
|