Hi I just want to program a DC bot and I keep getting this error
/root/invite_tracker_bot/index.js:5
Intents.FLAGS.GUILDS,
^
TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (/root/invite_tracker_bot/index.js:5:17)
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
Node.js v20.5.1
I've done npm install discord.js several times but it doesn't work nodejs is also the latest version I have no idea what the error is.
if you want to see the code say it
i Hope you can help me
btw. sorry for my bad English
i want to run the DC bot
the Code:
const { Client, Intents, MessageEmbed } = require('discord.js');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
// Add more intents here, if needed
]
});
const prefix = '/'; // The prefix for bot commands
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', async message => {
if (message.author.bot) return; // Prevent the bot from responding to its own messages
if (!message.content.startsWith(prefix)) return; // Ignore messages without prefix
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'setchannel') {
// Check if the command was sent by an administrator
if (!message.member.permissions.has('ADMINISTRATOR')) {
return message.reply('You do not have permission to execute this command.');
}
// Check if a channel was mentioned
const mentionedChannel = message.mentions.channels.first();
if (!mentionedChannel) {
return message.reply('You must mention a channel to set it as an invitation link channel.');
}
// Save the mentioned channel in a database or a global variable
// For example: botConfig.inviteChannel = mentionedChannel.id;
// Note that you need to implement the database integration according to your needs
message.reply(`The invitation link channel has been set to ${mentionedChannel}.`);
}
if (command === 'getinvites') {
// Get the invitations for the server
const invites = await message.guild.fetchInvites();
// Search for the desired invitation link
const targetInvite = invites.find(invite => invite.url === 'YOUR_INLINK');
if (!targetInvite) {
return message.reply('The specified invitation link was not found.');
}
// Get the number of joined members via this link
const joinedMembers = targetInvite.uses || 0;
// Calculate the remaining time of the invitation
const currentTime = new Date();
const expirationTime = targetInvite.expiresAt || currentTime; // If the invitation does not expire
const timeDifference = expirationTime - currentTime;
const remainingTime = timeDifference > 0 ? timeDifference / 1000 : 0; // In seconds
// Create an embed with the information
const embed = new Discord.MessageEmbed()
.setTitle('Invitation Link Information')
.setDescription(`Invitation link: ${targetInvite.url}\nNumber of joined: ${joinedMembers}\nTime remaining: ${remainingTime} Seconds`)
.setColor('#3498db'); // sample color, you can customize it
message.channel.send({ embeds: [embed] });
}
});
client.login('Here is my actual token');