"Started refreshing 0 application (/) commands."

Hello! I'm having trouble with a really stubborn issue in my code and I'm honestly pretty stumped. I have a minimal, but decent understanding of JS, and I'm using a command handler based on the official DJS guide + a DJS v14 tutorial that I've modified to suit the needs of my bot. My console doesn't log any errors, but despite there being a 'ping.js' command in a subfolder of the 'cmds' folder, it doesn't seem to recognize the file as an application command. I logged the file paths in the console and it's reading them just fine, but it still isn't registering 'ping.js' as a command file. I'll post my command handler and console log in a follow-up message.
5 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Wicked ↝ 💊Ⅶ✥
This is my command handler code:
const { REST, Routes } = require('discord.js');
const fs = require('fs');

module.exports = (client) => {

const { cmds } = client;

client.cmdsHandler = async () => {
const cmdFolders = fs.readdirSync(`./src/cmds`)

for (const folder of cmdFolders) {

const cmdFiles = fs.readdirSync(`./src/cmds/${folder}`).filter(file => file.endsWith('.js'));

for (const file of cmdFiles) {

const cmd = require(`../../cmds/${folder}/${file}`);

cmds.set(cmd.data.name, cmd);

}

console.log(cmdFolders, cmdFiles);

};

const clientId = 'REDACTED';
const rest = new REST().setToken(process.env.token);

(async () => {
try {
const data = await rest.put(
Routes.applicationCommands(clientId, cmds)
);

console.log(`Started refreshing ${data.length} application (/) commands.`);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();

}

};
const { REST, Routes } = require('discord.js');
const fs = require('fs');

module.exports = (client) => {

const { cmds } = client;

client.cmdsHandler = async () => {
const cmdFolders = fs.readdirSync(`./src/cmds`)

for (const folder of cmdFolders) {

const cmdFiles = fs.readdirSync(`./src/cmds/${folder}`).filter(file => file.endsWith('.js'));

for (const file of cmdFiles) {

const cmd = require(`../../cmds/${folder}/${file}`);

cmds.set(cmd.data.name, cmd);

}

console.log(cmdFolders, cmdFiles);

};

const clientId = 'REDACTED';
const rest = new REST().setToken(process.env.token);

(async () => {
try {
const data = await rest.put(
Routes.applicationCommands(clientId, cmds)
);

console.log(`Started refreshing ${data.length} application (/) commands.`);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();

}

};
And this is what my console logs (as you can see, it includes the file paths that I mentioned before, so I know it's reading them alright):
[ 'utility' ] [ 'ping.js' ]
Started refreshing 0 application (/) commands.
Successfully reloaded 0 application (/) commands.
Lupin is open for business :)
[ 'utility' ] [ 'ping.js' ]
Started refreshing 0 application (/) commands.
Successfully reloaded 0 application (/) commands.
Lupin is open for business :)
Additionally, I've searched this server for answers related to the title of this post, and none of them have gotten me any further.
Amgelo
Amgelo9mo ago
const data = await rest.put( Routes.applicationCommands(clientId, cmds) );
routes doesn't take two arguments, it only takes one, the client id; check how the guide puts commands and replicate that. (your second argument, cmds, should actually be the second argument of rest.put, but read below)
cmds.set(cmd.data.name, cmd);
it seems like cmds is a collection (or a map) and you're trying to post that same cmds variable. rest doesn't take a map as an argument so that'd fail, it takes an array of command data instead (inside an object), either save the data in a separate array or pass the values of the collection, check the guide as well for that
d.js docs
d.js docs9mo ago
:method: Collection#values() Returns an iterable of values in the map :mdn: Array.from() The Array.from() static method creates a new, shallow-copied Array instance from an iterable or array-like object.
Wicked ↝ 💊Ⅶ✥
Understood, I’ll try those edits and see if that fixes it. Thanks so much! :)
Want results from more Discord servers?
Add your server