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.
const Discord = require('discord.js');
// const Discord = require('discord.js');
// Using Intents class
const client = new Discord.Client();
client.on('message', (msg) => {
// Send back a reply when the specific command has been written by a user.
if (msg.content === '!hello') {
msg.reply('Hello, World!');
}
});
client.login('my_token');
This is the error I am getting:
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
Discord.js v14:
const client = new Discord.Client({ intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages
]})
Discord.js v13:
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })
Here's another useful page: Gateways
npm install node@16
in shell.