Justin
Justin
DIAdiscord.js - Imagine an app
Created by Justin on 10/18/2024 in #djs-questions
New commands only appear after completely removing and re-adding bot from servers
This is my deploy-commands.js: const { REST, Routes } = require('discord.js'); const { clientId, token } = require('./config.json'); const fs = require('fs'); const path = require('path'); const commands = []; const loadCommands = (dir) => { const files = fs.readdirSync(dir); for (const file of files) { const filePath = path.join(dir, file); if (fs.statSync(filePath).isDirectory()) { console.log(Entering directory: ${filePath}); // Debugging info loadCommands(filePath); // Recursive call for subfolders } else if (file.endsWith('.js')) { console.log(Loading command: ${filePath}); // Debugging info const command = require(filePath); commands.push(command.data.toJSON()); } } }; const foldersPath = path.join(__dirname, 'commands'); loadCommands(foldersPath); const rest = new REST({ version: '10' }).setToken(token); (async () => { try { console.log('Started refreshing application (/) commands.'); // Register commands globally await rest.put( Routes.applicationCommands(clientId), { body: commands }, ); console.log('Successfully reloaded global application (/) commands.'); } catch (error) { console.error(error); } })(); Can anyone spot why this might stop commands from being added without kicking the bot out and then adding it back in?
5 replies