-1

My code is fine and everything is fine but i get an error on discord.js last version

The error:

const bot = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] });
                                                          ^
TypeError: Cannot read properties of undefined (reading 'FLAGS')
    at Object.<anonymous> (C:\Users\SasYT\Documents\DiscordBOTS\GDPS\bot.py:3:60)
    at Module._compile (node:internal/modules/cjs/loader:1233:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

My code:

const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
    intents: [ [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] });


bot.once('ready', () => {
  console.log('Bot is ready!');
});
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
SasniySas
  • 1
  • 1
  • 2
    Does this answer your question? [Discord.js v13 code breaks when upgrading to v14](https://stackoverflow.com/questions/73028854/discord-js-v13-code-breaks-when-upgrading-to-v14) – Zsolt Meszaros Jul 28 '23 at 13:51
  • Does this answer your question? [Cannot read properties of undefined (reading 'guilds') on discord.js v14](https://stackoverflow.com/questions/76676659/cannot-read-properties-of-undefined-reading-guilds-on-discord-js-v14) – waki285 Jul 29 '23 at 04:21

1 Answers1

1

In discord.js v14, you need to use GatewayIntentBits

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

client.once('ready', () => {
  console.log('Bot is ready!');
});
waki285
  • 338
  • 1
  • 11
  • It's clearly a duplicate. Please, don't answer the same questions [again and again](https://stackoverflow.com/a/76679329/6126373), you should flag them as duplicates instead. – Zsolt Meszaros Jul 28 '23 at 14:33