import { REST, Routes } from "discord.js"; const { TOKEN, CLIENT_ID, GUILD_ID } = require("./config.json"); const fs = require("fs"); const path = require("path"); // set static commands const commands = [ { name: "pick", description: "Automatically picks teams", }, { name: "autocaptain", description: "Automatically picks teams", }, ]; // get commands from files const commandsPath = path.join(__dirname, "commands"); const commandFiles = fs.readdirSync(commandsPath); for (const file of commandFiles) { const command = require(`./commands/${file}`); if ("data" in command && "execute" in command) { let commandData = command.data; commands.push(commandData); if (command.synonyms) { for (const synonym of command.synonyms) { commands.push({ ...commandData, name: synonym, }); } } } else { console.error(`${__filename}: Invalid command file: ${file}`); } } const rest = new REST({ version: "10" }).setToken(TOKEN); try { console.log("Started refreshing application (/) commands."); // application reload await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands, }); // guild reload, faster than application reload //await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { // body: commands, //}); // clear guild commands //await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { // body: [], //}); console.log("Successfully reloaded application (/) commands."); } catch (error) { console.error(error); }