I want to make another command handler for my bot but I can’t.
I’ve tried this code:
module.exports = (client) => {
let dateNow = Date.now();
try {
readdirSync("./commands/").forEach((dir) => {
const commands = readdirSync(`./commands/${dir}/`).filter((file) =>
file.endsWith(".js")
);
for (let file of commands) {
try {
let pull = require(`../commands/${dir}/${file}`);
if (pull.name) {
client.commands.set(pull.name, pull);
} else {
continue;
}
} catch (e) {
console.log(e);
}
}
});
} catch (e) {
console.log(e);
}
};
But It’s not working. and I am getting an error:
Error: Cannot find module '../config.json'
Require stack:
- C:UsersPooyanDesktopPDM BotcommandsUtilityyoutube.js
- C:UsersPooyanDesktopPDM Bothandlerscommand_handler.js
- C:UsersPooyanDesktopPDM Botmain.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Object.<anonymous> (C:UsersPooyanDesktopPDM BotcommandsUtilityyoutube.js:4:16)
at C:UsersPooyanDesktopPDM Bothandlerscommand_handler.js:13:22
at module.exports (C:UsersPooyanDesktopPDM Bothandlerscommand_handler.js:7:32)
at C:UsersPooyanDesktopPDM Botmain.js:57:37
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\Users\Pooyan\Desktop\PDM Bot\commands\Utility\youtube.js',
'C:\Users\Pooyan\Desktop\PDM Bot\handlers\command_handler.js',
'C:\Users\Pooyan\Desktop\PDM Bot\main.js'
]
}
and +100 more errors…
Notes: I also tried to read articles and other questions on stack overflow and other websites, bot It did not work out. I am using discord.js v13 and Node.js v16
Extra Notes: My files are like this: