Slash commands not being created

Sorry I know this has been posted multiple times before and it must be getting old by now, but I read many posts and none of the answers I found worked for me. I am using the latest version of D.JS and Node. I have followed the tutorial to create a bot, but the slash commands simply don't show up at all. I tried restarting my Discord client several times, restarting the bot, removing the app, adding it back, etc. it just won't do anything. I am not sure what am I missing. When I run the deploy-commands.js file it says it worked successfully. I am, however, using a .env file, whereas the tutorial uses a .json file. But still I don't see how this changes anything. Let me know if you want any specific code or anything. Thanks for reading! Sorry again for the inconvenience.
5 Replies
d.js toolkit
d.js toolkit2d 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
Trooper
TrooperOP2d ago
const dotenv = require('dotenv');
const fs = require('node:fs');
const path = require('node:path');

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

const commands = [];
const envPath = path.join(__dirname, 'process.env');

dotenv.config({ path: envPath });

// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
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.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(process.env.TOKEN);

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

const data = await rest.put(
Routes.applicationCommands(process.env.CLIENTID),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
const dotenv = require('dotenv');
const fs = require('node:fs');
const path = require('node:path');

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

const commands = [];
const envPath = path.join(__dirname, 'process.env');

dotenv.config({ path: envPath });

// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
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.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(process.env.TOKEN);

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

const data = await rest.put(
Routes.applicationCommands(process.env.CLIENTID),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
No description
Trooper
TrooperOP2d ago
Here it is!
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};
Nope. Already checked the integrations tab too It just doesn't appear Yes and it's online. I also disconnected and waited for it to come offline before reloading and still nothing I did invite it with permissions for bot and applications.commands Yeah I did and it's correct, unless it has to be written in a different way. I tried both just a numeral and as a "" string in the .env file It outputs fine Sure, one moment Interesting I am not sure if this matters but guildid is null
Collection(1) [Map] {
'1331920108490326056' => <ref *1> ApplicationCommand {
id: '1331920108490326056',
applicationId: '1331900440740364360',
guild: null,
guildId: null,
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: null,
guildId: null,
commandId: '1331920108490326056'
},
type: 1,
nsfw: false,
name: 'ping',
nameLocalizations: null,
nameLocalized: null,
description: 'Replies with Pong!',
descriptionLocalizations: null,
descriptionLocalized: null,
options: [],
defaultMemberPermissions: null,
dmPermission: true,
integrationTypes: [ 1 ],
contexts: null,
version: '1331920108490326057'
}
}
Collection(1) [Map] {
'1331920108490326056' => <ref *1> ApplicationCommand {
id: '1331920108490326056',
applicationId: '1331900440740364360',
guild: null,
guildId: null,
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: null,
guildId: null,
commandId: '1331920108490326056'
},
type: 1,
nsfw: false,
name: 'ping',
nameLocalizations: null,
nameLocalized: null,
description: 'Replies with Pong!',
descriptionLocalizations: null,
descriptionLocalized: null,
options: [],
defaultMemberPermissions: null,
dmPermission: true,
integrationTypes: [ 1 ],
contexts: null,
version: '1331920108490326057'
}
}
Oh that must be it! I got very confused with that whole thing
d.js docs
d.js docs2d ago
If you have duplicate commands on your server, you registered both global and guild commands. You can remove the duplicates by resetting either the global or guild commands - Resetting global commands: rest.put(Routes.applicationCommands(clientId), { body: [] }) - Resetting guild commands: rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
Trooper
TrooperOP2d ago
That worked! Thanks so much! Sorry for the inconvenience

Did you find this page helpful?