#scandir problem

1 messages · Page 1 of 1 (latest)

alpine blaze
#

do you use __dirname ?

#

@elfin pawn

elfin pawn
#

I use this ```fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
const event = require(./events/${file});
let eventName = file.split(".")[0];
bot.on(eventName, event.bind(null, bot));
});
});

elfin pawn
#

It check for events folder like its set to ../events/

alpine blaze
#

where is events located

elfin pawn
alpine blaze
#

try using fs.readdirSync(path.join(__dirname, "events")

#

also import path (no instalation needed)

elfin pawn
#

Path?

alpine blaze
#

it doesn't have caps tho

elfin pawn
alpine blaze
#

wth have you done

elfin pawn
#

I dont get it xd

alpine blaze
#

i think make the function (err , files)

#
fs.readdir(path.join("./", "events"), (err, files) => {
    if (err) return console.error(err);
    files.forEach(file => {
        const event = require(`./events/${file}`);
        let eventName = file.split(".")[0];
        bot.on(eventName, event.bind(null, bot));
    });
});
#

@elfin pawn try this

elfin pawn
#

Ok

#

Doesnt work

#

ReferenceError: path is not defined

alpine blaze
#

I SAID IMPORT path

#

DIDN'T I?

elfin pawn
#

Oh

#

Error: Cannot find module './events'

alpine blaze
#

ok try __dirname instead of "./"

elfin pawn
#

ReferenceError: path is not defined

alpine blaze
#

why didn't import path yet

elfin pawn
#

Const path = require("./events/ready") | TypeError: path.join is not a function

alpine blaze
#

const without caps

elfin pawn
#

Const path = require("./events/") | Error: Cannot find module './events/'

#

Its without caps, just discord plugin

alpine blaze
#

also it's const path = require("path")

#

I didn't say import path from events

elfin pawn
#

Ohhh

alpine blaze
#

you need to learn node.js basics

elfin pawn
#

This works

elfin pawn
#

But idk why it wants folder name

alpine blaze
#

idt you need it

#

only if your file located in another folder in the directory

elfin pawn
# elfin pawn

Discord-bot folder is in folder and it was checking that folder and not where is that script located

alpine blaze
#

try put "./" instead you can reverse if it doesn't work

elfin pawn
#

I did that before

alpine blaze
#

ok ig your problem solved imma archive this thread