Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

722
Vistas
Error: ENOTDIR: not a directory, scandir error on interactionCreate

All of my files from Commands are read in fine but I get an error from 'interactionCreate.jslocated inEvents`

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

Error: ENOTDIR: not a directory, scandir './Events/interactionCreate.js'

My Event.js file is as follows:

const { readdirSync } = require('fs');
const ascii = require('ascii-table');
let table = new ascii("Events");
table.setHeading('EVENTS', ' LOAD STATUS');

module.exports = (client) => {
    readdirSync('./Events/').forEach(dir => {
        const events = readdirSync(`./Events/${dir}`).filter(file => file.endsWith('.js'));
        for(let file of events) {
            let pull = require(`../Events/${dir}/${file}`);
            if(pull.name) {
                client.events.set(pull.name, pull);
            } else {
                table.addRow(file, 'EVENT REGISTERED')
                continue;
            } if(pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach(alias => client.aliases.set(alias, pull.name))
        }
    });
    console.log(table.toString());
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your problem is here:

    readdirSync('./Events/').forEach(dir => {
        const events = readdirSync(`./Events/${dir}`)

readdirSync will return all the entries in the Events dir, that includes both files and directories. You've named your variable dir but they aren't all dirs. This is evidenced by the error message which specifically states ./Events/interactionCreate.js is not a directory.

Either remove non-dirs from your Events directory (i.e. move that file), or better, check if dir is in fact a directory before calling readdirSync on it.

The easiest way to do that is to add the {withFileTypes: true} option, and then you can call dir.isDirectory()

See docs https://nodejs.org/api/fs.html#fsreaddirsyncpath-options

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda