Home > Blockchain >  Error: ENOENT: no such file or directory, scandir discord bot
Error: ENOENT: no such file or directory, scandir discord bot

Time:10-17

I am new to making discord bots but I decided to give it a go. I watched a tutorial and copied the code but it doesn't work for me and I got this error:

    node:internal/fs/utils:347
    throw err;
    ^

Error: ENOENT: no such file or directory, scandir './src/functions/${folder}'
    at Object.readdirSync (node:fs:1438:3)
    at Object.<anonymous> (C:\Users\Redux Gamer\Desktop\Js\discord\univenture\src\bot.js:12:30)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47 {
  errno: -4058,
  syscall: 'scandir',
  code: 'ENOENT',
  path: './src/functions/${folder}'
}

I have looked this up and everyone is saying to do this:

npm update
npm install
node node_modules/node-sass/scripts/install.js
npm rebuild node-sass

I tried this and a lot of other things multiple times but it doesn't work. Here is my 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)

CodePudding user response:

Wrong quote. You are using

'

but it should be

`

Notice the difference in the styling of these two snippets:

`./src/functions/${folder}`
'./src/functions/${folder}'

You IDE for sure is highlighting it in the wrong way

  • Related