const fs = require("node:fs"); const { REST, Routes } = require("discord.js"); const { token } = require('./config.json'); const { exec } = require('child_process'); const rest = new REST({ version: "9" }).setToken(token); const appID = '898850107892596776'; console.log('building...'); exec('pnpm tsc', (err, stdout, stderr) => { if (err) throw err; console.log(stdout); const commands = []; const commandFiles = fs.readdirSync("./dist/commands").filter((file) => file.endsWith(".js") && !file.startsWith('.')); for (const file of commandFiles) { const command = require(`./dist/commands/${file}`); commands.push(command); } const knownServers = require('./dist/lib/knownServers').knownServers; const servers = [...new Set(Object.values(knownServers).reduce((a, b) => a.concat(b), []))]; for (const id of servers) { const serverCommands = commands.filter(command => command.serverWhitelist && command.serverWhitelist.includes(id)); rest .put(Routes.applicationGuildCommands(appID, id), { body: serverCommands.map(cmd => cmd.data.toJSON()) }) .then(() => console.log(`${serverCommands.length} commands added to ${id}`)) .catch(console.error); } const globalCommands = commands.filter(command => !command.serverWhitelist); rest .put(Routes.applicationCommands(appID), { body: globalCommands.map(cmd => cmd.data.toJSON()) }) .then(() => console.log(`${globalCommands.length} commands added globally, might take a bit to refresh`)) .catch(console.error); });