ENOENT: no such file or directory, scandir

Hello. Everything in my code was running smoothly until I did ‘npm run test’ which is telling me ‘Error: ENOENT: no such file or directory, scandir’.

Run down of my code where it is coming from is:

const functionFolders = fs.readdirSync(“./src/functions/”);
for (const folder of functionFolders) {
const functionFiles = fs
.readdirSync(“…/src/functions/${file}”)
.filter((file) => file.endsWith(‘.js’));
for (const file of functionFiles)
require(‘./functions/handlers/${file}’)(client);
}

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

Would be great if someone could help!

what call was giving that error?

odd things about the code:

  • ...
  • file referenced outside of its scope

did you write this yourself?

Not to sure why it put ‘…’, in the code it is just ‘.’. I’m half writing this myself and half following a guide too as I haven’t really done this in a long time.

phew, . makes more sense

combining into this reply: come to think of it, ./functions/handlers/${file} is also weird with the path being so different from all the readdir calls

Well the updated code now is:

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

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

And I get:

TypeError: client.handleEvents is not a function

Any ideas?

can you explain the changes here? e.g. why does the loop at the bottom not even use file? it just does the same thing repeatedly based on how many files are found