1

I'm trying to make a discord bot using discord.js (I have discord.js installed) but for some reason, I keep getting this weird error. I've looked through similar articles that address the same issue and suggested that I update my version of NodeJS to 16.6.0 or above (which I did) but have been unable to solve my issue. Any help would be much appreciated. Thank you.

code:

const Discord = require("discord.js")
const client = new Discord.Client()

client.on("ready", () => {
  console.log('Logged in as', client.user.tag)
})

client.on("message", msg => {
  if (msg.content == "ping") {
    msg.reply("pong");
  }
})

client.login(process.env.TOKEN)

error:

Error: Cannot find module 'node:events'
Require stack:
- /home/runner/name_file/node_modules/discord.js/src/client/BaseClient.js
- /home/runner/name_file/node_modules/discord.js/src/index.js
- /home/runner/name_file/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> (/home/runner/name_file/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)
Vndom
  • 13
  • 1
  • 3
  • Does this answer your question? [error when requiring discordjs - cannot find module 'node:events'](https://stackoverflow.com/questions/69489101/error-when-requiring-discordjs-cannot-find-module-nodeevents) – MrMythical Nov 12 '21 at 15:51
  • I read that particular question and updated my version of node.js to v16.13.0 after reading the answer, but I still keep getting the same error :(. – Vndom Nov 12 '21 at 17:37

2 Answers2

0

Read this. This is definitely related to your Node.js version. If you did upgrade, check the version: type node -v in your command prompt / terminal and see what version it shows. Once I also had problems with node.js upgrades.

Tadas
  • 355
  • 2
  • 16
  • Thank you for your response! Indeed, I checked my version and it says v16.13.0. If I recall correctly, I believe discord.js requires versions of NodeJS that are newer or equal to v16.6.0. Hmmm. Not sure why it's not working :(. – Vndom Nov 12 '21 at 07:11
  • So your update of node.js didn't happen? Could you tell me your steps you are doing to upgrade? If you are doing using npm - what output do you get? Windows / MAC / Linux? – Tadas Nov 12 '21 at 07:25
  • Oh, I'm really not sure what's happening :(. I'm using repl.it for my project and so I used the code and instructions given here: https://dev.to/arnavkr/updating-node-js-to-16-in-replit-1ep0. It's weird and trippy because it says that the version of node.js is v16.13.0 but for some reason the discord.js stuff still isn't working. – Vndom Nov 12 '21 at 17:33
0

I came to know you are using replit. So you may uninstall discord.js from the replit Packages (you can find it in left bar t). And go to package.json change discord.js version 12.5.3 . "discord.js": "^12.5.3",. Then open shell and install discord.js@12.5.3 with npm install discord.js@12.5.3. After installing , run your code . It should work ! Thank You

httpanand
  • 216
  • 2
  • 17