#when I do node deploy-commands.js nothing happens in the terminal

63 messages · Page 1 of 1 (latest)

rocky acornBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • 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
modest spade
#

is your code saved

lean hearth
#

yes

modest spade
#

and do you actually have logs inside that code

lean hearth
#

yes do you wanna see the script

modest spade
#

that would be useful yes

lean hearth
#

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);
}
};

modest spade
#

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

craggy anvilBOT
#

guide Creating Your Bot: Registering slash commands
read more

modest spade
#

not to mention the latest api version is 10

#

which is default if you omit it

lean hearth
#

its not the right version

#

?

modest spade
#

the latest api version is 10

#

but regardless, thats not your issue

lean hearth
#

so how do I fix this

modest spade
#

read the guide i linked

lean hearth
#

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

modest spade
#

yes

craggy anvilBOT
#

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!');

modest spade
#

thats indeed the code in the guide

lean hearth
#

so it should work now?

#

or will there be a error with the index.js

modest spade
#

have you tried it

lean hearth
#

its not working

#

@modest spade

#

i saved it too

modest spade
#

define not working, and no need to ping me

lean hearth
#

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

modest spade
#

you're trying to read a file as a directory

#

the guide expects you to have subfolders

lean hearth
#

wdym

modest spade
#

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

lean hearth
#

theres already subfolders

modest spade
#

show your file structure

lean hearth
modest spade
#

yeah you do not have subfolders

lean hearth
#

what are sub folders

modest spade
#

folders inside other folders

#

so inside of your commands folder

lean hearth
#

so I put deploy command - js in a folder inside of that folder

modest spade
#

...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

lean hearth
#

idk how to make the code do that

modest spade
#

do you know js

lean hearth
#

no

modest spade
#

then #rules 3 #resources

lean hearth
modest spade
#

no

lean hearth
#

im confused

modest spade
#

but if you dont know any js, you wont get support

#

a solid understanding is required