diff --git a/commands/test/ping.js b/commands/test/ping.js index 3b8965a..76fc71f 100644 --- a/commands/test/ping.js +++ b/commands/test/ping.js @@ -3,7 +3,7 @@ const { SlashCommandBuilder } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('ping') - .setDescription('Replies with pong.'), + .setDescription('This replies with pong.'), async execute(interaction) { await interaction.reply('Pong!'); } diff --git a/deploy-commands.js b/deploy-commands.js index e69de29..3794f0b 100644 --- a/deploy-commands.js +++ b/deploy-commands.js @@ -0,0 +1,45 @@ +const { REST, Routes } = require('discord.js'); +const { clientID, token } = require('./config.json'); +const fs = require('node:fs'); +const path = require('node:path'); + +const informationStatus = "[INFO]: "; +const warningStatus = "[WARNING]: "; +const errorStatus = "[ERROR]: "; + +const commands = []; +const foldersPath = path.join(__dirname, 'commands'); +const commandFolders = fs.readdirSync(foldersPath); + +for (const folder of commandFolders) { + const commandsPath = path.join(foldersPath, folder); + const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); + + for (const file of commandFiles) { + const filePath = path.join(commandsPath, file); + const command = require(filePath); + if ('data' in command && 'execute' in command) { + commands.push(command.data.toJSON()); + } else { + console.log(warningStatus + `This file at ${filePath} does not contain data or execute properties, will be ignored.`); + } + } +} + +const rest = new REST().setToken(token); + +(async () => { + try { + console.log(informationStatus + `Beginning deploy commands for ${commands.length} commands!`); + + const data = await rest.put( + Routes.applicationCommands(clientID), + { body: commands }, + ); + + console.log(informationStatus + `Loaded all ${data.length} commands!`); + } catch (error) { + console.log(errorStatus + `Something went wrong while trying to load commanads! Refer to the error below to debug.`); + console.error(error); + } +})();