I know that this question has been asked for discord.py, but couldn t find a discord.js one
Currently I m working on a small Discord Bot, and I would like to make it with possible that it can be used in multiple servers. I m used to the way a bot works in a single server, as I ve often made custom bots for a single server usage. But this time, as I m planning on making the bot public, I would like to make it multi-server enabled, so that multiple people can use it at the same time.
On a side note, I ve recently got access to Clyde AI on Discord, and so I used it to help me making this code :
src/deploy-commands.js
const { REST, Routes } = require( discord.js );
const { clientId, token } = require( ./../config.json );
const fs = require( node:fs );
const path = require( node:path );
const commands = [];
const commandsPath = path.join(\__dirname, commands );
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);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: 10 }).setToken(token);
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
The problem that I ve with that code, is that it doesn t load any commands into the servers, it just says :
Started refreshing/reloaded 0 application (/) commands.
I tried to load the commands using node deploy-commands.js
(which is the file that I pasted above) in the bot s servers, and I was expecting the console.log to tell me that it correctly loaded all the commands.
It s important to mention that I also removed my guildId from the config.json to enable multi-server usage.
Here are the other code snippets in case you want to see the whole code :
https://codefile.io/f/sKxpBG2uyU - index.js
https://codefile.io/f/YysJDHeJKA - track.js (slash command I m trying to load)
So to be honest, I m not sure where to look to fix my error, and where I can update my code to make it work on a multi-server usage.
If anyone of you has an idea, I will greatly take it.
I really hope someone is able to explain me how to make this work. Thanks in advance.