const { REST } = require("@discordjs/rest"); const { Routes } = require("discord.js"); const fs = require("fs"); require("dotenv").config(); const CLIENT_ID = "1011645201913217034"; const GUILD_ID = "1000491242108502186"; module.exports = (client) => { client.handleCommands = async () => { client.commandArray = []; const commandFolders = fs.readdirSync("./src/commands"); for (folder of commandFolders) { const commandFiles = fs.readdirSync(`./src/commands/${folder}`).filter(file => file.endsWith(".js")); for (const file of commandFiles) { const command = require(`../../commands/${folder}/${file}`); client.commands.set(command.data.name, command); client.commandArray.push(command.data.toJSON()); }; }; }; const rest = new REST({ version: "10" }).setToken(process.env.BOT_TOKEN); (async () => { try { await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: client.commandArray } ); console.log("[REGISTERED] Registed commands."); } catch (error) { console.log(error); } })(); };