Error: ENOTDIR for no reason

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);
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);
22 Replies
d.js toolkit
d.js toolkit13mo 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!
∞ | Dark
error :
[WARNING] The command at C:\Users\computer\Desktop\Bot\commands\moderation\prune.js is missing a required "data" or "execute" property.
node:internal/fs/utils:350
throw err;
^

Error: ENOTDIR: not a directory, scandir 'C:\Users\AHMED\Desktop\X Bot\commands\server.js'
at Object.readdirSync (node:fs:1527:3)
at Object.<anonymous> (C:\Users\AHMED\Desktop\X Bot\index.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\\computer\\Desktop\\Bot\\commands\\server.js'
}

Node.js v18.17.0
PS C:\Users\computer\Desktop\X Bot>
[WARNING] The command at C:\Users\computer\Desktop\Bot\commands\moderation\prune.js is missing a required "data" or "execute" property.
node:internal/fs/utils:350
throw err;
^

Error: ENOTDIR: not a directory, scandir 'C:\Users\AHMED\Desktop\X Bot\commands\server.js'
at Object.readdirSync (node:fs:1527:3)
at Object.<anonymous> (C:\Users\AHMED\Desktop\X Bot\index.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\\computer\\Desktop\\Bot\\commands\\server.js'
}

Node.js v18.17.0
PS C:\Users\computer\Desktop\X Bot>
treble/luna
treble/luna13mo ago
ypu're scanning a file as a directory, not djs related either
∞ | Dark
i just followd discord.js decomentation
treble/luna
treble/luna13mo ago
well, the guide expects you to have subfolders
∞ | Dark
wait 1m now commands isnt working
treble/luna
treble/luna13mo ago
define isnt working
∞ | Dark
explain more pls
treble/luna
treble/luna13mo ago
i am asking you that i'm not much with 'isnt working that can also mean you just dont run your bot at all
∞ | Dark
i run it by running
node index.js
node index.js
treble/luna
treble/luna13mo ago
yeah thats not what i asked i asked what doesnt work
∞ | Dark
the "/" commands
treble/luna
treble/luna13mo ago
did you deploy them
∞ | Dark
how do i do that ??
d.js docs
d.js docs13mo ago
guide Creating Your Bot: Registering slash commands read more
Want results from more Discord servers?
Add your server