const commands = []
const commandFolders = fs.readdirSync('./commands');
for (const folder of commandFolders) {
const folderPath = `./commands/${folder}`;
const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`${folderPath}/${file}`);
commands.push(command.data.toJSON());
}
}```
#Error: ENOENT: no such file or directory, scandir './commands'
23 messages · Page 1 of 1 (latest)
Error: ENOENT: no such file or directory, scandir './commands'
file structure and command handler code for deploy-commands.js
error:
fs reads relative paths from working dir
i dont really know why fs cant find that path
working dir is where you start the process from, which is (probably) the one package.json is in
./ will refer to that directory, which has no "commands" folder
I tried changing it to ```js
const commands = []
const commandFolders = fs.readdirSync('../src/commands');
again, it starts at the current working directory.
so now you are moving one folder out of that (../), which probably doesn't even have a src
ah
ah ok
now i understand
having this now here is the updated code:```js
const commands = []
const commandFolders = fs.readdirSync('./src/commands');
for (const folder of commandFolders) {
const folderPath = ./src/commands/${folder};
const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(${folderPath}/${file});
commands.push(command.data.toJSON());
}
}```
require reads from the module it is used in, not cwd
try that
Client.commands = new Discord.Collection()
const commandFolders = fs.readdirSync(`./commands/`).sort((a, b) => {
return parseInt(a.match(/\d+/)) - parseInt(b.match(/\d+/))
})
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js')).sort((c, d) => {
return parseInt(c.match(/\d+/)) - parseInt(d.match(/\d+/))
})
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`)
Client.commands.set(command.name, command)
console.log(`Command load: ${command.name} [${folder}]`)
}
}
try this ⬇️
dont spoonfeed
😉
const commands = []
const commandFolders = fs.readdirSync('./src/commands');
for (const folder of commandFolders) {
const folderPath = `./src/commands/${folder}`;
const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../src/commands/${folder}/${file}`);
commands.push(command.data.toJSON());
}
}```
did this
solved the issue
you dont need all that stuff just needed to fix the paths