From c908a524aac6e16da1791564389df4c4d5f77dd3 Mon Sep 17 00:00:00 2001 From: Supositware Date: Thu, 13 Oct 2022 16:32:58 +0200 Subject: [PATCH] Fix deploy --- scripts/deploy-commands.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/scripts/deploy-commands.js b/scripts/deploy-commands.js index c5e19e7..7735976 100644 --- a/scripts/deploy-commands.js +++ b/scripts/deploy-commands.js @@ -9,16 +9,20 @@ const { clientId, guildId, token } = process.env; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); - const commands = []; + const categoryPath = fs.readdirSync(`${__dirname}/../commands`); -categoryPath.forEach(category => { - loadCommandFromDir(category); -}); -commands.map(command => command.toJSON()); +for (let i = 0; i < categoryPath.length; i++) { + const commandsPath = path.join(`${__dirname}/../commands`, categoryPath[i]); + const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); + for (const file of commandFiles) { + const filePath = path.join(commandsPath, file); + const command = await import(filePath); + commands.push(command.default.data.toJSON()); + } +} const rest = new REST({ version: '9' }).setToken(token); - if (process.argv[2] === 'global') { rest.put(Routes.applicationCommands(clientId), { body: commands }) .then(() => console.log('Successfully registered application commands globally.')) @@ -33,15 +37,3 @@ else if (process.argv[2] === 'delete') { rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) .then(() => console.log(`Successfully registered application commands for the guild ${guildId}.`)) .catch(console.error); - -async function loadCommandFromDir(dir) { - const commandsPath = path.join(`${__dirname}/../commands`, dir); - const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); - - for (const file of commandFiles) { - const filePath = path.join(commandsPath, file); - let command = await import(filePath); - command = command.default; - commands.push(command.data); - } -} \ No newline at end of file