Error: Cannot find module 'node:events'

I am getting an error pretty annoying after with pnpm enabled

_ internal/modules/cjs/loader.js:613
throw err;
^
Error: Cannot find module ‘node:events’
Require stack:

  • /rbd/pnpm-volume/16525bb6-dbbe-4958-b828-3b1d10d691cc/node_modules/.registry.npmjs.org/discord.js/13.2.0/node_modules/discord.js/src/client/BaseClient.js
  • /rbd/pnpm-volume/16525bb6-dbbe-4958-b828-3b1d10d691cc/node_modules/.registry.npmjs.org/discord.js/13.2.0/node_modules/discord.js/src/index.js
    Jump To- /app/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
    at Function.Module._load (internal/modules/cjs/loader.js:526:27)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object. (/rbd/pnpm-volume/16525bb6-dbbe-4958-b828-3b1d10d691cc/node_modules/.registry.npmjs.org/discord.js/13.2.0/node_modules/discord.js/src/client/BaseClient.js:3:22)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions…js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module.load (internal/modules/cjs/loader.js:555:12)
    at Module.require (internal/modules/cjs/loader.js:666:19)

Package.json:

{
“name”: “discord-bot”,
“version”: “1.0.0”,
“description”: “Discord Bot Made By Oofin”,
“main”: “index.js”,
“scripts”: {
“test”: “echo "Error: no test specified" && exit 1”,
“start”: “node index.js”
},
“engines”: {
“node”: “12.16.1”
},
“author”: “”,
“license”: “ISC”,
“dependencies”: {
@discordjs/opus”: “^0.6.0”,
@mapbox/node-pre-gyp”: “^1.0.5”,
@top-gg/sdk”: “^3.1.2”,
“aki-api”: “^6.0.8”,
“amethyste-api”: “^1.1.5”,
“axios”: “^0.23.0”,
“bindings”: “^1.5.0”,
“bufferutil”: “^4.0.5”,
“canvas”: “^2.8.0”,
“canvas-constructor”: “^5.0.1”,
“cheerio”: “^0.22.0”,
“common-tags”: “^1.8.0”,
“dblapi.js”: “^2.4.1”,
“discord”: “^0.8.2”,
“discord-akairo”: “^8.1.0”,
“discord-anti-spam”: “^2.5.8”,
“discord.js”: “^13.2.0”,
“discordutility”: “^1.0.0”,
“express”: “^4.17.1”,
“ffmpeg”: “^0.0.4”,
“ffmpeg-static”: “^4.4.0”,
“figlet”: “^1.5.2”,
“fs”: “^0.0.2”,
“fs-nextra”: “^0.5.1”,
“get-artist-title”: “^1.3.1”,
“giphy-api”: “^2.0.2”,
“got”: “^11.8.2”,
“http”: “^0.0.0”,
“humanize-duration”: “^3.27.0”,
“install”: “^0.13.0”,
“iso-639-1”: “^2.1.9”,
“jimp”: “^0.16.1”,
“math”: “^0.0.3”,
“mathjs”: “^9.5.1”,
“ms”: “^2.1.3”,
“node-fetch”: “^3.0.0”,
“node-gyp”: “^8.3.0”,
“node-gyp-build”: “^4.3.0”,
“node-opus”: “^0.3.3”,
“node-superfetch”: “^0.2.3”,
“opusscript”: “^0.0.8”,
“parse-ms”: “^3.0.0”,
“path”: “^0.12.7”,
“peer”: “^0.6.1”,
“pnpm”: “^6.19.0”,
“pokersolver”: “^2.1.4”,
“prism-media”: “^1.3.2”,
“quick.db”: “^7.1.3”,
“random-puppy”: “^1.1.0”,
“ref”: “^1.3.5”,
“relevant-urban”: “^2.0.0”,
“simple-youtube-api”: “^5.2.1”,
“utf-8-validate”: “^5.0.6”,
“util”: “^0.12.4”,
“weather-js”: “^2.0.0”,
“wikijs”: “^6.3.2”,
“ws”: “^8.2.3”,
“node-libpng”: “^0.2.20”,
“events”: “^3.3.0”,
“node-events”: “^0.0.2”
},
“devDepenyodencies”: {}
}

I would appreciate help!

With some testing I figured that the problem is also related to my main js file:

const {
Client,
MessageAttachment,
Collection,
MessageEmbed
} = require(“discord.js”);
const { PREFIX, TOKEN, DBL_API_KEY } = require(“./config”);
const bot = new Client({ disableMentions: “everyone” });
const DBL = require(“dblapi.js”);
const dbl = new DBL(DBL_API_KEY);
const fs = require(“fs”);
const db = require(“quick.db”);
const jimp = require(“jimp”);
const Discord = require(“discord.js”);
const got = require(“got”);
const humanizeDuration = require(‘humanize-duration’);
bot.cooldowns = new Discord.Collection();

bot.phone = new Collection();
bot.commands = new Collection();
bot.aliases = new Collection();
bot.snipes = new Discord.Collection();

[“aliases”, “commands”].forEach(x => (bot = new Collection()));
[“console”, “command”, “event”].forEach(x => require(./handler/${x})(bot));

bot.categories = fs.readdirSync(“./commands/”);

[“command”].forEach(handler => {
require(./handler/${handler})(bot);
});

bot.on(“ready”, () => {
setInterval(() => {
dbl.postStats(bot.guilds.cache.size);
}, 1800000);
});

bot.on(“message”, async message => {
let prefix;
if (message.author.bot || message.channel.type === “dm”) return;
try {
let fetched = await db.fetch(prefix_${message.guild.id});
if (fetched == null) {
prefix = PREFIX;
} else {
prefix = fetched;
}
} catch (e) {
console.log(e);
}

if (message.author.bot) return;
if (message.channel.type === “dm”) return;

let messageFetch = db.fetch(guildMessages_${message.guild.id});
if (messageFetch === null) return;

db.add(messages_${message.guild.id}_${message.author.id}, 1);
let messagefetch = db.fetch(
messages_${message.guild.id}_${message.author.id}
);

let messages;
if (messagefetch == 0) messages = 0;
//Level 0
else if (messagefetch == 100) messages = 100;
// Level 1
else if (messagefetch == 200) messages = 200;
// Level 2
else if (messagefetch == 300) messages = 300;
// Level 3
else if (messagefetch == 400) messages = 400;
// Level 4
else if (messagefetch == 500) messages = 500;
// Level 5
else if (messagefetch == 600) messages = 600;
// Level 6
else if (messagefetch == 700) messages = 700;
// Level 7
else if (messagefetch == 800) messages = 800;
// Level 8
else if (messagefetch == 900) messages = 900;
// Level 9
else if (messagefetch == 1000) messages = 1000;
// Level 10
else if (messagefetch == 1100) messages = 1100;
// Level 11
else if (messagefetch == 1200) messages = 1200;
// Level 12
else if (messagefetch == 1300) messages = 1300;
// Level 13
else if (messagefetch == 1400) messages = 1400;
// Level 14
else if (messagefetch == 1500) messages = 1500;
// Level 15
else if (messagefetch == 1600) messages = 1600;
// Level 16
else if (messagefetch == 1700) messages = 1700;
// Level 17
else if (messagefetch == 1800) messages = 1800;
// Level 18
else if (messagefetch == 1900) messages = 1900;
// Level 19
else if (messagefetch == 2000) messages = 2000;
// Level 20
else if (messagefetch == 2100) messages = 2100;
// Level 21
else if (messagefetch == 2200) messages = 2200;
// Level 22
else if (messagefetch == 2300) messages = 2300;
// Level 23
else if (messagefetch == 2400) messages = 2400;
// Level 24
else if (messagefetch == 2500) messages = 2500;
// Level 25
else if (messagefetch == 2600) messages = 2600;
// Level 26
else if (messagefetch == 2700) messages = 2700;
// Level 27
else if (messagefetch == 2800) messages = 2800;
// Level 28
else if (messagefetch == 2900) messages = 2900;
// Level 29
else if (messagefetch == 3000) messages = 3000;
// Level 30
else if (messagefetch == 3100) messages = 3100;
// Level 31
else if (messagefetch == 3200) messages = 3200;
// Level 32
else if (messagefetch == 3300) messages = 3300;
// Level 33
else if (messagefetch == 3400) messages = 3400;
// Level 34
else if (messagefetch == 3500) messages = 3500;
// Level 35
else if (messagefetch == 3600) messages = 3600;
// Level 36
else if (messagefetch == 3700) messages = 3700;
// Level 37
else if (messagefetch == 3800) messages = 3800;
// Level 38
else if (messagefetch == 3900) messages = 3900;
// Level 39
else if (messagefetch == 4000) messages = 4000;
// Level 40
else if (messagefetch == 4100) messages = 4100;
// Level 41
else if (messagefetch == 4200) messages = 4200;
// Level 42
else if (messagefetch == 4300) messages = 4300;
// Level 43
else if (messagefetch == 4400) messages = 4400;
// Level 44
else if (messagefetch == 4500) messages = 4500;
// Level 45
else if (messagefetch == 4600) messages = 4600;
// Level 46
else if (messagefetch == 4700) messages = 4700;
// Level 47
else if (messagefetch == 4800) messages = 4800;
// Level 48
else if (messagefetch == 4900) messages = 4900;
// Level 49
else if (messagefetch == 5000) messages = 5000; // level 50

if (!isNaN(messages)) {
db.add(level_${message.guild.id}_${message.author.id}, 1);
let levelfetch = db.fetch(level_${message.guild.id}_${message.author.id});

let levelembed = new MessageEmbed()
.setColor(“GREEN”)
.setDescription(
**${message.author}, You Have Leveled Up To Level ${levelfetch}**
)
.setFooter(${prefix}disablexp To Disable Level Up Messages);
message.channel.send(levelembed);
}
});

bot.on(“message”, async message => {
let prefix;
try {
let fetched = await db.fetch(prefix_${message.guild.id});
if (fetched == null) {
prefix = PREFIX;
} else {
prefix = fetched;
}
} catch (e) {
console.log(e);
}
try {
if (
message.mentions.has(bot.user) &&
!message.mentions.has(message.guild.id)
) {
return message.channel.send(
**My Prefix In This Server is - \${prefix}`**`
);
}
} catch {
return;
}
});

bot.on(“message”, async message => {
try {
const hasText = Boolean(message.content);
const hasImage = message.attachments.size !== 0;
const hasEmbed = message.embeds.length !== 0;
if (message.author.bot || (!hasText && !hasImage && !hasEmbed)) return;
const origin = bot.phone.find(
call => call.origin.id === message.channel.id
);
const recipient = bot.phone.find(
call => call.recipient.id === message.channel.id
);
if (!origin && !recipient) return;
const call = origin || recipient;
if (!call.active) return;
await call.send(
origin ? call.recipient : call.origin,
message,
hasText,
hasImage,
hasEmbed
);
} catch {
return;
}
});

const express = require(“express”);
const app = express();

const dreams = [
“Find and count some sheep”,
“Climb a really tall mountain”,
“Wash the dishes”
];
app.use(express.static(“public”));

app.get(“/”, (request, response) => {
response.sendFile(__dirname + “/views/index.html”);
});

app.get(“/dreams”, (request, response) => {
response.json(dreams);
});

const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});

bot.on(‘message’, (message) => {

if(message.content && message.content.toLowerCase() === ‘oli is dumb’) {
message.reply(‘GG, YOU FOUND THE SECRET COMMAND :D. Dm Oofin_404’);
}
});

bot.login(process.env.TOKEN);

I assume you are still having issues. Is this your first Discord bot? You seem to have nearly one of everything in the dependencies list.

So your issue appears to be that you are using “discord.js”: “^13.2.0” but are using an older version of node: “node”: “12.16.1”

If you check the following link you will see you need version 16.6.0 or newer

If it helps:
you’ve misspelled devDependencies as “devDepenyodencies”: {}

You seem to have at least three message handlers
bot.on(“message”, async message => {

the following checks do the same thing:

if (message.author.bot || message.channel.type === “dm”) return;

if (message.author.bot) return;
if (message.channel.type === “dm”) return;

and finally in your very large if… else statement you assign what is effectively the messagefetch value to messages

let messages;
if (messagefetch == 0) messages = 0;
//Level 0
else if (messagefetch == 100) messages = 100;
// Level 1
else if (messagefetch == 200) messages = 200;

1 Like

Got another issue when did this but I will just make another topic!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.