error
I have done codes of basic slash commands, but when i try to run node deploy-commands.js, this error appears:
Error: ENOTDIR: not a directory, scandir 'C:\Users\fanmo\OneDrive\Plocha\taubine\commands\ping.js'
at Object.readdirSync (node:fs:1527:3)
at Object.<anonymous> (C:\Users\fanmo\OneDrive\Plocha\taubine\deploy-commands.js:14:26)
at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 { errno: -4052, syscall: 'scandir', code: 'ENOTDIR', path: 'C:\Users\fanmo\OneDrive\Plocha\taubine\commands\ping.js' }
at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 { errno: -4052, syscall: 'scandir', code: 'ENOTDIR', path: 'C:\Users\fanmo\OneDrive\Plocha\taubine\commands\ping.js' }
40 Replies
- 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!Node.js v18.17.1
you're scanning a file as directory, or the directory doesnt exist
so how to fix it
fix your file structure
or fix your file scanning
your code expects your commands to be in a subfolder probably
well i can execute commands not but "The application did not respond"
do you listen for the interactionCreate event
wdym (sry im really amateur)
show your index.js file
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
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) {
client.commands.set(command.data.name, command);
} else {
console.log(
[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.
);
}
}
}
client.once(Events.ClientReady, () => {
console.log('Ready!');
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.login(token);and do you get any output?
is your client ready
and online
bot is online
log your
command
variable right before your if(!command) statementmy index.js looks like that rn: const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
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) {
client.commands.set(command.data.name, command);
} else {
console.log(
[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.
);
}
}
}
const eventsPath = path.join(dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.login(token);and do you have an events folder
y
interactionCreate.js and ready.js
If you aren't getting any errors, try to place
console.log
checkpoints throughout your code to find out where execution stops.
- Once you do, log relevant values and if-conditions
- More sophisticated debugging methods are breakpoints and runtime inspections: learn moreI give up ig
do what i said
and show your interactionCreate file
const { Events } = require('discord.js');
module.exports = {
name: Events.ClientReady,
once: true,
execute(client) {
console.log(
Ready! Logged in as ${client.user.tag}
);
},
};thats not your interactionCreate
const { Events } = require('discord.js');
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(
No command matching ${interaction.commandName} was found.
);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(Error executing ${interaction.commandName}
);
console.error(error);
}
},
};log your command variable
I'm back
client.on('interactionCreate', async (interaction) => {
// Your existing code here
// Logging the 'command' variable
console.log(command);
// Rest of your code here
}); ?
basically
assuming you actually kept your previous code
well it's the same
and what does it log
now this pops-up: Error: Cannot find module '../config.json'
Require stack:
- C:\Users\fanmo\OneDrive\Plocha\taubine\index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at Module._load (node:internal/modules/cjs/loader:922:27)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:121:18)
at Object.<anonymous> (C:\Users\fanmo\OneDrive\Plocha\taubine\index.js:4:19)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'C:\Users\fanmo\OneDrive\Plocha\taubine\index.js' ]
}
Node.js v18.17.1
you didn't create a config.json then
but I have
when i returned to the project, i didnt change anything from that
uh
i just give up ig
also, there's a difference between ./ and ../
..
you can clearly see
well there's your issue
its ./
?
../ is not ./
its rather basic js to know the difference
nvm
also, how did you even find out from image
because your stack shows you used ../