My simple test code
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const { MessageEmbed, channels } = require('discord.js');
client.login('no peeking');
client.on('ready', readyUser);
function readyUser(){
console.log('Bot is ready and logged in');
}
client.on("messageCreate", (message) => {
const prefix = "!";
const args = message.content.substring(prefix.length).split(" ");
const command = args.shift().toLowerCase();
if (message.author.id != client.user.id) {
}
});
gives error
TypeError: Cannot read properties of undefined (reading 'FLAGS')
regarding line 2.
From what I found, this could be caused by my intents being disabled in Discord developer portal. Even though I enabled them and the problem is still in place.
What I found (enabled intents)
CodePudding user response:
In discord.js v14, you 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,
// ...
]
})
CodePudding user response:
If you're using v14 of discord.js, Intents
are no longer available.
You'll need to use GatewayIntentBits
instead:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
]
});