I'm tired of this because I can't fix it. It doesn't register. I will follow this gudie https://discordjs.guide/interactions/registering-slash-commands.html#global-commands
const command = require(path.join(__dirname, '..', 'commands', 'slash') + '/' + files)
console.log(command.name + " Is Register")
let cmd = command.register();
commandsList.push(cmd)
console.log(commandsList)
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands("894136598982180905"),
{ body: commandsList },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
I will log SlashCommandBuilder show this commandsList
[
{
name: 'ping',
description: 'Ping Commands',
options: [],
default_permission: undefined
}
]
Slash Command Builder File
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
name: "Ping",
register() {
const data = new SlashCommandBuilder().
setName("ping")
.setDescription("Ping Commands")
.toJSON();
return data;
},
};
As MrMythical correctly mentioned, most commonly it happens when you didn't give application. commands scope for the bot's invite link.
If it's your case - kick the bot from your server, and create a new link with bot and application. commands scopes, give proper permission set and re-invite it again.
But I've just had the same issue even though it was properly invited (and has worked before). For me, the solution was to regenerate the Token at Discord Developer Portal and restart the bot with the new token. After that - it again works like a charm.