TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (/home/runner/SomeDigitalHacks/index.js:2:47)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
const { Client, Intents, MessageEmbed } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const token = '<please use secrets>';
const categoryChannelId = '1117159362952171690';
client.once('ready', () => {
console.log('Bot is ready');
});
client.on('messageCreate', async (message) => {
if (message.author.bot || !message.content.startsWith('/')) return;
const [command, ...args] = message.content.slice(1).split(' ');
if (command === 'submit_vod') {
const firstQuestion = args.join(' ');
const guild = client.guilds.cache.get(message.guild.id);
const categoryChannel = guild.channels.cache.get(categoryChannelId);
if (!categoryChannel || !categoryChannel.isCategory()) {
console.error('Category channel not found');
return;
}
const formChannel = await guild.channels.create(firstQuestion, {
type: 'text',
parent: categoryChannel,
topic: `Discussion forum for ${firstQuestion}`,
});
const formSubmissionEmbed = new MessageEmbed()
.setTitle(firstQuestion)
.addField('User', message.author.tag)
.addField('Question', message.content);
formChannel.send({ embeds: [formSubmissionEmbed] })
.then(() => {
message.channel.send('Form submission created successfully!');
})
.catch((error) => {
console.error('Failed to send form submission:', error);
});
}
});
client.login(token);
According to this, just do this:
const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
// ...
]
})
I removed your token as showing it online basically gives anyone access, and even in your real code I recommend using secrets even if your repl is private.
2 Likes