In Discord.js
v14, Intent is deprecated. If you try to use Intents.FLAGS.GUILDS
then it will raise TypeError: Cannot read properties of undefined (reading ‘FLAGS’). Instead you will need to use GatewayIntentBits.Guilds
.
Solution with Code Example
Wrong Code – Let’s first show you the wrong part of the code –
const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [ Intents.FLAGS.GUILDS ] });
Since Intents
is deprecated so we can’t use it anymore. Discord.js
has provided GatewayIntentBits
in it’s place.
Correct Code
const { Client, GatewayIntentBits } = require('discord.js'); const client = new Client({ intents: [ GatewayIntentBits.Guilds ] });
This will solve your issue of TypeError: Cannot read properties of undefined (reading ‘FLAGS’).