Updating commands once the bot is started.

I've looked at various posts but no one seems to help me, when I start my bot with the command “node .” my bot goes online correctly however it doesn't update the commands by adding the ones I created, staying on the old ones, even if I go to “Manage interaction” it doesn't change and they are still the same, I don't get any errors in my code.
18 Replies
d.js toolkit
d.js toolkit2mo 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!
d.js docs
d.js docs2mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2mo ago
:guide: Creating Your Bot: Registering slash commands read more
Cristiano®
Cristiano®OP2mo ago
Yes but nothing.
treble/luna
treble/luna2mo ago
wdym nothing
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/luna2mo ago
also did you refresh your discord client
Cristiano®
Cristiano®OP2mo ago
Yes.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Cristiano®
Cristiano®OP2mo ago
No description
treble/luna
treble/luna2mo ago
that code does not register your commands you were told how
Cristiano®
Cristiano®OP2mo ago
But why do the other commands work? Always slash.
treble/luna
treble/luna2mo ago
you deployed them at some point
Cristiano®
Cristiano®OP2mo ago
const { REST } = require("@discordjs/rest");
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');

const clientId = '1321817952462573639';
const guildId = '563099392371064833';

module.exports = (client) => {
client.handleCommands = async (commandFolders, path) => {
client.commandArray = [];
for (folder of commandFolders) {
const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
client.commands.set(command.data.name, command);
client.commandArray.push(command.data.toJSON());
}
}

const rest = new REST({
version: '9'
}).setToken(process.env.token);

(async () => {
try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationCommands(clientId), {
body: client.commandArray
},
);

console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
};
};
const { REST } = require("@discordjs/rest");
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');

const clientId = '1321817952462573639';
const guildId = '563099392371064833';

module.exports = (client) => {
client.handleCommands = async (commandFolders, path) => {
client.commandArray = [];
for (folder of commandFolders) {
const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
client.commands.set(command.data.name, command);
client.commandArray.push(command.data.toJSON());
}
}

const rest = new REST({
version: '9'
}).setToken(process.env.token);

(async () => {
try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationCommands(clientId), {
body: client.commandArray
},
);

console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
};
};
Do you mean this?
treble/luna
treble/luna2mo ago
yes also the latest api version is 10 and that code should not need a client it should be ran separately whenever you change your commands
Cristiano®
Cristiano®OP2mo ago
So how should I solve the problem?
treble/luna
treble/luna2mo ago
by running the file but removing your client logic from it

Did you find this page helpful?