After successfully installing node.js, I proceeded to type the command 'npm init' in the command prompt and then installed discord.js. However, upon installation of discord.js, a 'node_modules' folder was not added inside the project, which I believe is causing the issue. When attempting to bring my bot online using the command 'node main.js', I encountered the following error message: Error:
Cannot find module 'discord.js'
Require stack:
- C:\Users\Cookie\Desktop\bot\main.js
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:778:27)←[39m
←[90m at Module.require (node:internal/modules/cjs/loader:1005:19)←[39m
←[90m at require (node:internal/modules/cjs/helpers:102:18)←[39m
at Object.<anonymous> (C:\Users\Cookie\Desktop\bot\main.js:1:17)
←[90m at Module._compile (node:internal/modules/cjs/loader:1101:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [ ←[32m'C:\\Users\\Cookie\\Desktop\\bot\\main.js'←[39m ]
}
The contents of my package.json file are as follows:
{
"name": "bot",
"version": "1.0.0",
"description": "test",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Cookie482",
"license": "ISC",
"dependencies": {
"discord.js": "*"
}
As for the content of main.js:
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('bot is online');
});
client.login('bot-token');