Click here to Skip to main content
16,021,823 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Bot.js code:
require("dotenv").config();
const { token } = process.env;
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const fs = require("fs");

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

const functionFolders = fs.readdirSync(`./src/functions`);
for (const folder of functionFolders) {
  const functionFiles = fs
    .readdirSync(`./src/functions/${folder}`).filter((file) => file.endsWith(".js"));
  for (const file of functionFiles)
    require(`./functions/${folder}/${file}`)(client);
}

client.handleEvents();
client.handleCommands();
client.login(token);


handleEvents.js
const { Events } = require("discord.js");
const fs = require("fs");

module.exports = (client) => {
  client.handleEvents = async () => {
    const eventFolders = fs.readdirSync(`./src/events`);
    for (const folder of eventFolders) {
      const eventFiles = fs
        .readdirSync(`./src/events/${folder}`)
        .filter((file) => file.endsWith(".js"));
      switch (folder) {
        case "client":
            for (const file of eventFiles) {
                const event = require(../../src/Events/${folder}/${file});
                if (event.once) client.once(event.name, (...args) => event.execute(...args, client));
                else client.on(event.name, (...args) => event.execute(...args, client));
                
            }  
            break;
      
        default:
            break;
      }
    }
  };
};





ERROR:
> hyperbot@1.0.0 test
> node .

node:internal/modules/cjs/loader:998
  throw err;
  ^

Error: Cannot find module '.src/functions/handlers/handleCommands.js'
Require stack:
- C:\Users\Admin\Desktop\HyperBot\src\bot.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Users\Admin\Desktop\HyperBot\src\bot.js:15:5)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\Admin\\Desktop\\HyperBot\\src\\bot.js' ]
}

Node.js v18.12.1


What I have tried:

I have tried changing from
const event = require(../../src/Events/${folder}/${file});


to

const event = require(src/Events/${folder}/${file});
Posted
Updated 2-Jan-23 10:13am
v2
Comments
Graeme_Grant 2-Jan-23 10:07am    
open a command prompt, navigate to the execution [root] path, then use your path fragment and try to change dir to it...
Chaz O 2-Jan-23 10:10am    
Thanks for the response. Without asking you to spoonfeed - could you please be a little more specific in command?
Graeme_Grant 2-Jan-23 10:13am    
dos:
cd [path fragment goes here]

WIN+R > cmd.exe

You do know how to change to the root path for your app right?
Chaz O 2-Jan-23 10:38am    
i understand dos commands i just wasn't sure what you meant by path fragment. Where should i cd to?

changing root path of my app... not off the top of my head, this is my first js bot man. Appreciate your time :)
Graeme_Grant 2-Jan-23 10:40am    
this is the path fragment:
../../src/Events/${folder}/${file}
It is not a fully qualified path but is valid from the current path if it points to a valid qualified path.

1 solution

Case-sensitive letter change in ./src/functions
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900