A discord bot for teal.fm
discord tealfm music
at main 1.1 kB view raw
1import { env } from "@tealfmbot/common/constants"; 2import { REST, Routes } from "discord.js"; 3import fs from "node:fs"; 4import path from "node:path"; 5 6const commands = []; 7const commandPaths = fs.globSync("dist/commands/*.js"); 8 9for await (const cmdPath of commandPaths) { 10 const absoluteCommandPath = path.join(import.meta.dirname, cmdPath); 11 const command = await import(absoluteCommandPath); 12 if ("data" in command.default && "execute" in command.default) { 13 commands.push(command.default.data); 14 } else { 15 console.warn( 16 `[Warning] The command at ${absoluteCommandPath} is missing a required "data" or "execute" property.`, 17 ); 18 } 19} 20 21const rest = new REST().setToken(env.DISCORD_BOT_TOKEN); 22 23(async () => { 24 try { 25 console.log(`Started refreshing ${commands.length} application (/) commands.`); 26 27 const data = (await rest.put( 28 Routes.applicationGuildCommands(env.DISCORD_APPLICATION_ID, env.DISCORD_GUILD_ID), 29 { body: commands }, 30 )) as unknown[]; 31 32 console.log(`Successfully reloaded ${data.length} application (/) commands.`); 33 } catch (error) { 34 console.error(error); 35 } 36})();