Error: Cannot find module 'discord.js' after updating node and npm

I have been stuck recently on my discord bot but thanks to tleylan. Unfortunately it generated another issue…

node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module ‘discord.js’
Require stack:
Jump To- /app/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
Jump Toat Object. (/app/index.js:6:5)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions…js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: ‘MODULE_NOT_FOUND’,
Jump TorequireStack: [ ‘/app/index.js’ ]

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”: “>=16.0.0”,
“npm”: “>= 7.0.0”
},
“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”
},
“devDependencies”: {}
}

Index.js:

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);

Helping will me amazing!

This is the 2nd time you have posted more than 100 lines of source. There is no way I can believe this used to work so why are you generating such large files while you try to figure out how to build a Discord bot?

The volume of code is only getting in your way. When was the last time you saw it build and run?

Is the syntax you found for specifying node? And did you find some docs that suggested specifying the version of npm?

“engines”: {
“node”: “>=16.0.0”,
“npm”: “>= 7.0.0”
},

Let me suggest that you eliminate 99% of the nonsense and get a simple project that builds properly. Then you can add the parts you want back in. You can easily detect if it breaks and make corrections before it becomes 20 problems.

Well it did used to work before any node update was available. This is the part confusing me and the fact that english is my third language makes the doc pretty confusing to read

It can be confusing but the idea is to try to reduce the code to something manageable and understandable so the confusion is reduced. There appears to be several issues with that code whether or not it used to work.

Again I suggest that you follow a simple tutorial that uses Discord.JS v13 as an example. If you can get a “hello world” bot running you should be able to see the code that is causing your problems in this project.

You might change your engines setting for starters, try:

“engines”: {
“node”: “^16.6.1”
}

Yea il’l try that but I may have found the error

Which was what? Perhaps someone else can learn from what you’ve found.

Well my project was actually broken… I just had to make another one and just copy paste and clean the unnecessary code I have