So i am creating a discord bot that will reply with messages from the gitbook i have. However when I run the program, I get the following error:
Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (C:\Users\91827\Desktop\real\bot.js:6:47)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
The code is:
const { Client, Intents } = require('discord.js');
const axios = require('axios');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '!';
// Event handler for when the bot is ready
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('messageCreate', async (message) => {
// Check if the message author is a bot or doesn't start with the prefix
if (message.author.bot || !message.content.startsWith(prefix)) return;
// Extract the command and arguments from the message
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'hackathon') {
const gitbookURL = args[0];
if (!gitbookURL || !gitbookURL.startsWith('LINK I'll ADD LATER')) {
message.reply('Please provide a valid guide URL.');
return;
}
try {
// GitBook URL
const response = await axios.get(gitbookURL);
const sections = response.data.sections || [];
const query = args.join(' ').toLowerCase();
// Find the section containing the query
let matchingSection = null;
sections.forEach((section) => {
if (section.content.toLowerCase().includes(query)) {
matchingSection = section;
}
});
if (matchingSection) {
// Reply with the matching section's title and link
message.reply(`Here is the information you requested:\nTitle: ${matchingSection.title}\nLink: ${gitbookURL}`);
} else {
// If no matching section found
message.reply('Sorry, I could not find information related to your query in this guide.');
}
} catch (error) {
console.error('Error fetching guide:', error);
message.reply('An error occurred while fetching the guide.');
}
} });
client.login('TOKEN, I have made hidden');
I am not able to find what is the problem? It is not able to read the flags. Used GPT but no fruitful response yet.