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._pile (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._pile (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.
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._pile (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._pile (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.
Share Improve this question asked Oct 6, 2021 at 18:33 Riya PalRiya Pal 551 silver badge5 bronze badges 3- 6 Does this answer your question? Nullish coalescing assignment operator (??=) in NodeJS – MrMythical Commented Oct 6, 2021 at 18:36
- This operator ( ??= ) was added in 2021 ( i.imgur./6XZ0jG1.png ), possibly putting the above version of the node will fix the problem – UKRman Commented Oct 6, 2021 at 18:38
- no the issue was, discord.js needs node version above 16.6 .... After I upgraded my version it started working fine – Riya Pal Commented Oct 8, 2021 at 17:22
2 Answers
Reset to default 6You have to update node.js to v16.6 or later, as per the docs (scroll down to "Installation").
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/#/docs/main/stable/general/wele