Application commands are not updated in chat, but in "Manage Integration" are up-to-date.

Here is my code that updates commands: When the bot starts to run, it loads all commands
client.commands = new Map();
const commandPath = './commands';
const commandFiles = fs.readdirSync(commandPath).filter((file) => file.endsWith('.mjs'));
for (const file of commandFiles) {
const filePath = './' + path.join(commandPath, file);
let command = await import(filePath);
command = command.default;

if (command.ignore) continue;
if (command.data && command.execute) {
client.commands.set(command.data.name, command);
} else {
console.error(`Error: ${filePath} command is missing a required property "data" or "execute"`);
}
}
client.commands = new Map();
const commandPath = './commands';
const commandFiles = fs.readdirSync(commandPath).filter((file) => file.endsWith('.mjs'));
for (const file of commandFiles) {
const filePath = './' + path.join(commandPath, file);
let command = await import(filePath);
command = command.default;

if (command.ignore) continue;
if (command.data && command.execute) {
client.commands.set(command.data.name, command);
} else {
console.error(`Error: ${filePath} command is missing a required property "data" or "execute"`);
}
}
After the bot is ready, it sets client.application.commands
import { Client, Events } from 'discord.js';

export default {
once: true,
name: Events.ClientReady,

/**
* execute
* @param {Client} client
*/
async execute(client) {
console.info('Client is Ready');

// load commands
const commands = Array.from(client.commands.values()).map(command => command.data.toJSON());
client.application.commands.set(commands)
.catch(console.error);

const commandNames = commands.map(command => command.name);
console.info(`Commands loaded: ${commandNames.join(', ')}`);
},
};
import { Client, Events } from 'discord.js';

export default {
once: true,
name: Events.ClientReady,

/**
* execute
* @param {Client} client
*/
async execute(client) {
console.info('Client is Ready');

// load commands
const commands = Array.from(client.commands.values()).map(command => command.data.toJSON());
client.application.commands.set(commands)
.catch(console.error);

const commandNames = commands.map(command => command.name);
console.info(`Commands loaded: ${commandNames.join(', ')}`);
},
};
Here's an example of my command file:
import { SlashCommandBuilder, CommandInteraction } from 'discord.js';

export default {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Reply with ms'),

/**
* execute
* @param {CommandInteraction} interaction
*/
async execute(interaction) {
await interaction.reply(`πŸ“ Ping! ${interaction.client.ws.ping}ms`);
},
};
import { SlashCommandBuilder, CommandInteraction } from 'discord.js';

export default {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Reply with ms'),

/**
* execute
* @param {CommandInteraction} interaction
*/
async execute(interaction) {
await interaction.reply(`πŸ“ Ping! ${interaction.client.ws.ping}ms`);
},
};
Discord.js Version: 14.7.1 Nodejs Version: 22.2.0
16 Replies
d.js toolkit
d.js toolkitβ€’5mo 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! - βœ… Marked as resolved by OP
731018913097449533
731018913097449533OPβ€’5mo ago
No description
731018913097449533
731018913097449533OPβ€’5mo ago
No description
731018913097449533
731018913097449533OPβ€’5mo ago
this is what I mean that commands are not "updated"
Kinect3000
Kinect3000β€’5mo ago
Did you try refreshing the app? That error means it’s still a registered command tho
731018913097449533
731018913097449533OPβ€’5mo ago
Yes, but when I check "Manage Integration", it does change.
Kinect3000
Kinect3000β€’5mo ago
"Yes" to that you tried refreshing? ctrl + r
731018913097449533
731018913097449533OPβ€’5mo ago
You are totally right. So I should refresh the app every time I update.... For users, that will be a hassle, I suppose. Any other way? Or should I register commands, and it will change instantly? I guess just refresh my discord Thank for the response, I will note that.
Dwxdynos
Dwxdynosβ€’5mo ago
hi guys do you know how to use discord.js please say
Amgelo
Amgeloβ€’5mo ago
you can try not to deploy on ready, only when you need it (like with an extra script, the guide has an example)
731018913097449533
731018913097449533OPβ€’5mo ago
Isn't that registering commands? I have no idea about the difference
Amgelo
Amgeloβ€’5mo ago
you can check the guide https://discordjs.guide
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Amgelo
Amgeloβ€’5mo ago
don't ask on random threads though, at least do it on #djs-help-v14 yes, in this context deploying/registering can mean the same thing, which is "sending" your command data to discord
731018913097449533
731018913097449533OPβ€’5mo ago
oh, I see What if I set guild.commands? will that be the same?
Amgelo
Amgeloβ€’5mo ago
that'd deploy/register your commands to only that guild what I meant was, given commands don't change that regularly, you can try manually deploying them when you know it's needed, not on every start
731018913097449533
731018913097449533OPβ€’5mo ago
Fair enough πŸ‘ Thank you
Want results from more Discord servers?
Add your server