[Fix] TypeError Cannot read properties of undefined (reading ‘FLAGS’)

The Error “TypeError: Cannot read properties of undefined (reading ‘FLAGS’)”, is an error that is invoked when you are working on discord.js. Given below is the snippet of the error you might get:

TypeError: Cannot read properties of undefined (reading 'FLAGS')

I would like to share with you the steps I took to fix the “TypeError: Cannot read properties of undefined (reading ‘FLAGS’)”.

Why “TypeError Cannot read properties of undefined (reading ‘FLAGS’)” Error is Seen?

The error, “TypeError: Cannot read properties of undefined (reading ‘FLAGS’)” is seen because, in the latest discord.js version that is version 14, the Intents import has been removed and does not exist more.

Rather you will need to use a GatewayIntentBits when you are declaring the intents inside the client.

The detailed solution to fix the error “TypeError: Cannot read properties of undefined (reading ‘FLAGS’)”, is given below:

How to Fix “TypeError: Cannot read properties of undefined (reading ‘FLAGS’)” Error?

To fix the error, you will need to use a GatewayIntentBits when you are declaring the intents inside the client. Once you define the GatewayIntentBits when you are declaring the intents inside the client, error TypeError: Cannot read properties of undefined (reading ‘FLAGS’) will be fixed.

To fix the error, “TypeError: Cannot read properties of undefined (reading ‘FLAGS’)”, you will have to follow the steps mentioned below:

First, you will need to use a GatewayIntentBits when you are declaring the intents inside the client. To do so in your project, you will have to use the below mentioned code as a reference:

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildPresences,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildMessageReactions,
  ],
});

You can find the list of all changed intents in discord.js version 14 from version v12/13, from the below table:

v12/v13v14
GUILDSGatewayIntentBits.Guilds
GUILD_BANSGatewayIntentBits.GuildBans
GUILD_EMOJIS_AND_STICKERSGatewayIntentBits.GuildEmojisAndStickers
GUILD_INTEGRATIONSGatewayIntentBits.GuildIntegrations
GUILD_INVITESGatewayIntentBits.GuildInvites
GUILD_MEMBERSGatewayIntentBits.GuildMembers
GUILD_MESSAGE_REACTIONSGatewayIntentBits.GuildMessageReactions
GUILD_MESSAGE_TYPINGGatewayIntentBits.GuildMessageTyping
GUILD_MESSAGESGatewayIntentBits.GuildMessages
GUILD_PRESENCESGatewayIntentBits.GuildPresences
GUILD_SCHEDULED_EVENTSGatewayIntentBits.GuildScheduledEvents
GUILD_VOICE_STATESGatewayIntentBits.GuildVoiceStates
GUILD_WEBHOOKSGatewayIntentBits.GuildWebhooks
DIRECT_MESSAGESGatewayIntentBits.DirectMessages
DIRECT_MESSAGE_TYPINGGatewayIntentBits.DirectMessageTyping
DIRECT_MESSAGE_REACTIONSGatewayIntentBits.DirectMessageReactions
N/AGatewayIntentBits.MessageContent

This should fix the error, “TypeError: Cannot read properties of undefined (reading ‘FLAGS’)”,

Conclusion

To fix the error, you will need to use a GatewayIntentBits when you are declaring the intents inside the client.

Once you define the GatewayIntentBits when you are declaring the intents inside the client, error TypeError: Cannot read properties of undefined (reading ‘FLAGS’) will be fixed.