oreb
June 10, 2024, 5:34pm
1
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!
wh0
June 10, 2024, 6:12pm
2
what call was giving that error?
odd things about the code:
...
file
referenced outside of its scope
did you write this yourself?
oreb
June 10, 2024, 6:43pm
3
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.
wh0
June 10, 2024, 6:54pm
4
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
oreb
June 10, 2024, 6:56pm
5
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?
wh0
June 10, 2024, 8:34pm
6
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
system
Closed
December 7, 2024, 8:34pm
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.