25

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:

Enter image description here

0

4 Answers 4

34

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


  • 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 client events are under the events tab at Client.
0
4

You can instead just degrade the discord.js version by typing this into the shell:

npm i discord.js@12.5.3

The latest discord.js version doesn't function very well, so I use v12. It isn't a complicated script.

2

Add Intents.

const { Client, Intents } = require('discord.js');
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

You can also use the template available in the discord.js documentation. Documentation

0
client = new Discord.Client({intents: 32767})
1
  • Where should that be applied? Replacing the second code line? Or something else? Can you extend your answer, please? But ********************** without ********************** "Edit:", "Update:", or similar - the answer should appear as if it was written today. Aug 23, 2022 at 21:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.