So I'm learning how to make bot on discord using discord.js
this is my bot.js
require("dotenv").config();
const { Client } = require('discord.js');
const client = new Client();
client.login(process.env.DISCORD_TOKEN_KEY);
this is my package.json file:
{
"name": "aibot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./src/bot.js",
"dev": "nodemon ./src/bot.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^13.2.0",
"dotenv": "^10.0.0"
}
}
So when I run node ./src/bot.js
I am getting this error:
PS E:\RIYA\AIBOT> node -v
v14.18.0
PS E:\RIYA\AIBOT> node ./src/bot.js
E:\RIYA\AIBOT\node_modules\discord.js\src\rest\APIRequest.js:33
agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
^^^
SyntaxError: Unexpected token '??='
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (E:\RIYA\AIBOT\node_modules\discord.js\src\rest\RESTManager.js:4:20)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
What shall I do? I don't know much about NodeJs and I'm not able to figure out how to solve this issue.
You need to update your Node to version 16.6.0 or newer to work and modify your
2nd and 3rd lines
of code to:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
To prevent
[Symbol(code)]: 'CLIENT_MISSING_INTENTS' error
Read More from the documentation https://discord.js.org/#/docs/main/stable/general/welcome