I started learning about discord.js, but now I am facing this issue. I tried some googling, but I couldn’t manage to fix it.
JavaScript
x
15
15
1
const Discord = require('discord.js');
2
// const Discord = require('discord.js');
3
4
// Using Intents class
5
const client = new Discord.Client();
6
7
client.on('message', (msg) => {
8
// Send back a reply when the specific command has been written by a user.
9
if (msg.content === '!hello') {
10
msg.reply('Hello, World!');
11
}
12
});
13
14
client.login('my_token');
15
This is the error I am getting:
Advertisement
Answer
You need to specify the events which you want your bot to receive using gateway intents.
Instead of
const client = new Discord.Client();
Use
const client = new Discord.Client({ intents: [Enter intents here] })
For example
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })
Here’s another useful page: Gateways
- Intents help you control which events your bot receives. See Privileged Intents for more information.
- You need node.js 16.6 or higher to use discord.js13.
npm install node@16
in shell. - The list of events are under the events tab at Client.