Hey everyone! I’m new to making Discord bots and I’m stuck. My classmate and I are trying to create a bot to track scholarship points for our school. We wrote some code with ChatGPT’s help but it’s not working.
When I run node bot.js, I get this error:
TypeError: Cannot read properties of undefined (reading 'FLAGS')
Here’s a snippet of our code:
const { Client, GatewayIntentBits } = require('discord.js');
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages
]
});
bot.login('SECRET_TOKEN');
let scholarshipPoints = {};
bot.on('ready', () => {
console.log(`Bot is online as ${bot.user.tag}!`);
});
bot.on('messageCreate', msg => {
// Bot logic here
});
Any ideas what’s causing this error? I’m using Node.js v20.11.1. Thanks for your help!
hey jackwolf, looks like ur having some trouble with the intents. make sure ur using the latest version of discord.js (v14+). if u are, try adding the MessageContent intent to ur list:
GatewayIntentBits.MessageContent
that should fix the FLAGS error. lmk if u need more help!
I’ve encountered similar issues when working on Discord bots. The error you’re seeing often stems from outdated dependencies or mismatched versions.
Double-check your discord.js version by running ‘npm list discord.js’ in your project directory. If it’s not v14+, update it with ‘npm install discord.js@latest’. After updating, you might need to adjust your code slightly since the Intents system changed in v14.
Also, ensure your bot has the necessary permissions in Discord’s Developer Portal, as sometimes the issue isn’t with the code but with the bot’s configuration. If you’re still stuck, posting your package.json content could help diagnose the problem.
The error you’re encountering suggests an issue with the Discord.js version or intents configuration. First, ensure you’re using Discord.js v14 or later by running ‘npm install discord.js@latest’. Then, modify your intents setup like this:
This should resolve the ‘FLAGS’ error. If problems persist, verify your bot token and check the Discord Developer Portal to ensure all necessary intents are enabled for your application. Let us know if you need further assistance after trying these steps.