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

Viewed 5403

my code is fine and everything is fine but i get an error.

My code:

const { Client, Intents } = require('discord.js');

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

client.once('ready', () => {
    console.log('Ready!');
  client.user.setPresence({ activities: [{ name: 'Discord' }], status: 'idle' });
});

client.login(process.env.token);

The error:

TypeError: Cannot read properties of undefined (reading 'FLAGS')
    at Object.<anonymous> (/home/runner/discordjs-bot/index.js:5:47)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)

Any help?

1 Answers

In discord.js v14, the Intents import does not exist. You instead, need to use GatewayIntentBits when declaring the intents in the client. An example would be something like this:

const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        // ...
    ]
})
Related