Slash Commands not showing up

I followed the discordjs.guide but when I type / in server, I can't see my bot's slash commands. deploy-commands.js:
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];

const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {

const commandsPath = path.join(foldersPath, folder);
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);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

const rest = new REST().setToken(token);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

const data = await rest.put(Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];

const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {

const commandsPath = path.join(foldersPath, folder);
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);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

const rest = new REST().setToken(token);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

const data = await rest.put(Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
12 Replies
d.js toolkit
d.js toolkit8mo 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
ShompiFlen
ShompiFlen8mo ago
what does the execution of the deployment script log to the console?
toasta
toasta8mo ago
this is the Discord.JS Guide (i use it so i can help)
toasta
toasta8mo ago
No description
toasta
toasta8mo ago
the reason your probably aren't seeing the slash commands are
1. you have to reload your Discord client 2. your bot is only pushing guild commands
and 2 is the answer based off of this here
const data = await rest.put(Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
const data = await rest.put(Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
this should be ur code
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
toasta
toasta8mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Ling Ling Eggroll
Ling Ling EggrollOP8mo ago
i dont see this everytime i run so something is still wrong i believe
duck
duck8mo ago
well if you're following the guide, the deployment script is purposefully a separate script that doesn't run when your bot runs you'd run it separately
ShompiFlen
ShompiFlen8mo ago
I wanted to see if they are successfully pushing commands to the api instead of guessing what is happening
Ling Ling Eggroll
Ling Ling EggrollOP8mo ago
:Thonk:
ShompiFlen
ShompiFlen8mo ago
did you successfully deploy the commands to the guild you specified in your config.json file? did you run this script?
Ling Ling Eggroll
Ling Ling EggrollOP8mo ago
it worked now ! thanks
Want results from more Discord servers?
Add your server