- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- 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 staff
#when I do node deploy-commands.js nothing happens in the terminal
63 messages · Page 1 of 1 (latest)
is your code saved
yes
and do you actually have logs inside that code
yes do you wanna see the script
that would be useful yes
here
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
module.exports = async (client) => {
console.log('Started deploying commands...');
// Ensure client.commands is populated and log it
console.log('Commands to deploy:', client.commands);
const commands = client.commands.map(command => command.data.toJSON());
const rest = new REST({ version: '9' }).setToken(client.token);
try {
console.log('Started refreshing application (/) commands.');
// Deploy commands to the Discord API
await rest.put(
Routes.applicationCommands(client.user.id),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error('Error deploying commands:', error);
}
};
that indeed wont produce any output
nor is it the correct way of deploying commands
it should be a separate script yes
so you do not need to export a function
so how do I fix this
read the guide i linked
this is the right code 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 = [];
// 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(token);
// and deploy your commands!
(async () => {
try {
console.log(Started refreshing ${commands.length} application (/) commands.);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
is this the right code
yes
Codeblocks:
```js
const Discord = require("discord.js");
// further code
```
becomes
const Discord = require("discord.js");
// further code
Inline Code:
`console.log('inline!');` becomes console.log('inline!');
thats indeed the code in the guide
have you tried it
define not working, and no need to ping me
node:fs:1507
const result = binding.readdir(
^
Error: ENOTDIR: not a directory, scandir 'C:\Users\amade\Desktop\goofy goobers the bot final\commands\addpoints.js'
at Object.readdirSync (node:fs:1507:26)
at Object.<anonymous> (C:\Users\amade\Desktop\goofy goobers the bot final\deploy-commands.js:14:26)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
errno: -4052,
code: 'ENOTDIR',
syscall: 'scandir',
path: 'C:\Users\amade\Desktop\goofy goobers the bot final\commands\addpoints.js'
}
Node.js v20.14.0
PS C:\Users\amade\Desktop\goofy goobers the bot final>
this is the error
you're trying to read a file as a directory
the guide expects you to have subfolders
wdym
exactly what i said
you're trying to read a file as a directory
so either change the code to read it as a file, or make subfolders
theres already subfolders
show your file structure
yeah you do not have subfolders
what are sub folders
so I put deploy command - js in a folder inside of that folder
...no
your commands are expected to be in subfolders
so either make subfolders inside your commands folder
or edit your code to not use subfolders and just scan the entire commands folder
idk how to make the code do that
do you know js
no
then #rules 3 #resources
alright
wait so the commands are suppose to be a index.js folder
no
im confused
Creating Your Bot: Registering slash commands