I wanted to make a discord bot, but didn't get very far because the code doesn't work which after multiple tutorials I still couldn't get working. This is the code I have and the error it gives. Can anyone please tell me what i might be doing wrong?
const { token } = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.login(xxxxxxxxxxxxxxxxxxxxxxxx);
-----------------------------------------------------------------
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './config.json'
Require stack:
- C:\Users\gabri\Documents\botdisc\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:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\gabri\Documents\botdisc\index.js:3:19)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975: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',
requireStack: [ 'C:\\Users\\gabri\\Documents\\botdisc\\index.js' ]
}
Node.js v17.0.1
CodePudding user response:
The javascript file can't find your config.json, check the path and make sure your config.json is in the same folder as your index.js