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

150
Vistas
Getting weird errors when running node index.js w/npm

Okay so I was trying to make a discord bot following a tutorial when I noticed some weird errors.

This is my code:

const Discord = require('discord.js');

const client = new Discord.Client();

const prefix = '-';

client.once('ready', () => {
    console.log('JokeBot is online!')
});

client.on('message', message => {
    if(!message.content.startsWith(prefix) || message.author.bot ) return;

    const args = message.content.slice(prefix.lenght).split(/ +/);
    const command = args.shift().toLowerCase();

    if(command === 'ping'){
        message.channel.send('pong!');
    }
});

client.login(YOUR_TOKEN);

And these are the errors:

Debugger attached.
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module 'node:events'
Require stack:
- /media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/client/BaseClient.js
- /media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/index.js
- /media/oli/MID/Projects/JS/Bot/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/client/BaseClient.js:3:22)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/client/BaseClient.js',
    '/media/oli/MID/Projects/JS/Bot/node_modules/discord.js/src/index.js',
    '/media/oli/MID/Projects/JS/Bot/index.js'
  ]
}
              

May I remind you that running npm install on those packages didn't work and just returned a lot of npm errors. I don't know what to do Edit:

It's still saying that even when I updated node.js

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I think the issue is happening because you are using nodejs less than version 16.6.0. discord.js requires node.js version more than or equal to 16.6.0. Try running node -v command in your terminal and that might be less than 16.6.0 then download and install that version of node.

Also add this in your package.json

"engines": {
  "node": ">=16.6.0"
}

Also, in your code, you misspelled length.

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar

0

in order to use discord.js. So You just need to update nodejs to v16.6. And Your error will be solved.

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