files not reading based on command handling (not a discord.js issue)

I'm new to djs and never made a bot with discord.js I'm facing an error with the code can anyone help me here's the code:-
js
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();

const foldersPath = path.join(__dirname, 'commands');
const isDirectory = fs.lstatSync(foldersPath).isDirectory();

if (!isDirectory) {
console.error(`${foldersPath} is not a directory`);
process.exit(1);
}

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);
// Set a new item in the Collection with the key as the command name and the value as the exported module
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, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});

// Log in to Discord with your client's token
client.login(token);
js
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();

const foldersPath = path.join(__dirname, 'commands');
const isDirectory = fs.lstatSync(foldersPath).isDirectory();

if (!isDirectory) {
console.error(`${foldersPath} is not a directory`);
process.exit(1);
}

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);
// Set a new item in the Collection with the key as the command name and the value as the exported module
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, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});

// Log in to Discord with your client's token
client.login(token);
Error:-
node:fs:1515

const result = binding.readdir(

Error: ENOTDIR: not a directory, scandir /home/runner/Nodejs-3/commands/ping.js' at Object.readdirSync (node:fs: 1515:26

)

at Object.<anonymous> (/home/runner/No dejs-3/index.js:15:26)
at Module._compile (node: internal/modu les/cjs/loader: 1376:14)
at Module._extensions..js (node:intern al/modules/cjs/loader: 1435:10)
at Module.load (node: internal/modules/ cjs/loader: 1207:32)
at Module._load (node:internal/modules /cjs/loader: 1023:12)
at Function.executeUserEntryPoint [as runMain] (node: internal/modules/run_main:1 35:12)
at node: internal/main/run_main_module: 28:49 {

errno: -20,
code: 'ENOTDIR',
syscall: 'scandir',
path: '/home/runner/Nodejs-3/commands/ping.js'
}
node:fs:1515

const result = binding.readdir(

Error: ENOTDIR: not a directory, scandir /home/runner/Nodejs-3/commands/ping.js' at Object.readdirSync (node:fs: 1515:26

)

at Object.<anonymous> (/home/runner/No dejs-3/index.js:15:26)
at Module._compile (node: internal/modu les/cjs/loader: 1376:14)
at Module._extensions..js (node:intern al/modules/cjs/loader: 1435:10)
at Module.load (node: internal/modules/ cjs/loader: 1207:32)
at Module._load (node:internal/modules /cjs/loader: 1023:12)
at Function.executeUserEntryPoint [as runMain] (node: internal/modules/run_main:1 35:12)
at node: internal/main/run_main_module: 28:49 {

errno: -20,
code: 'ENOTDIR',
syscall: 'scandir',
path: '/home/runner/Nodejs-3/commands/ping.js'
}
I code in replit I made the required folder and files but it still showing this error!
3 Replies
d.js toolkit
d.js toolkit8mo 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
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs8mo ago
:guide: Creating Your Bot: Command handling read more
Want results from more Discord servers?
Add your server