From 111787852f7c26afc490261cecdfbd49460929a1 Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 3 Apr 2023 11:27:44 +0200 Subject: [PATCH] Added seperarion for user and guild commands --- deploy-commands.js | 2 +- deploy-testing.js | 36 ++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 deploy-testing.js diff --git a/deploy-commands.js b/deploy-commands.js index 0d3bbea..6388828 100644 --- a/deploy-commands.js +++ b/deploy-commands.js @@ -24,7 +24,7 @@ const rest = new REST({ version: '10' }).setToken(token); // The put method is used to fully refresh all commands in the guild with the current set const data = await rest.put( - Routes.applicationGuildCommands(clientId, guildId), + Routes.applicationCommands(clientId), { body: commands }, ); diff --git a/deploy-testing.js b/deploy-testing.js new file mode 100644 index 0000000..579fbe8 --- /dev/null +++ b/deploy-testing.js @@ -0,0 +1,36 @@ +const { REST, Routes } = require('discord.js'); +const { clientId, guildId, token } = require('./config.json'); +const fs = require('node:fs'); + + +const commands = []; +// Grab all the command files from the commands directory you created earlier +const commandFiles = fs.readdirSync('./commands-testing').filter(file => file.endsWith('.js')); + +// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment +for (const file of commandFiles) { + const command = require(`./commands-testing/${file}`); + commands.push(command.data.toJSON()); +} + +// Construct and prepare an instance of the REST module +const rest = new REST({ version: '10' }).setToken(token); + + +// and deploy your commands! +(async () => { + try { + console.log(`Started refreshing ${commands.length} application (/) commands.`); + + // The put method is used to fully refresh all commands in the guild with the current set + const data = await rest.put( + Routes.applicationGuildCommands(clientId, guildId), + { body: commands }, + ); + + console.log(`Successfully reloaded ${data.length} application (/) commands.`); + } catch (error) { + // And of course, make sure you catch and log any errors! + console.error(error); + } +})(); diff --git a/package.json b/package.json index 3d78fdf..3a0046c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "rebuild": "node deploy-commands.js" + "prod:build": "node deploy-commands.js", + "dev:build": "node deploy-testing.js" }, "author": "Taken", "license": "ISC",