joel joel joel
This commit is contained in:
24
commands/register.ts
Normal file
24
commands/register.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user