-1

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');
Motofo20
  • 1
  • 4
  • 1
    Hy, welcome to Stack Overflow, please edit your question to contain all the information (code) - consider to use the editor's formatting options. Also see [How to Ask](https://stackoverflow.com/help/how-to-ask) – Daxelarne Aug 17 '23 at 08:00
  • Does this answer your question? [Discord.js v13 code breaks when upgrading to v14](https://stackoverflow.com/questions/73028854/discord-js-v13-code-breaks-when-upgrading-to-v14) – Zsolt Meszaros Aug 17 '23 at 12:23

1 Answers1

0

Based on the discord.js documentation, Intents seems to not exist but you can get Flags.GuildPresences, Flags.GuildMembers and Flags.Guilds from IntentsBitField.

You can find more about the IntentsBitField on the documenation or use the GatewayIntentBits wich allow you to directly get Guilds and GuildMessages. More on the GatewayIntentBits here

Daxelarne
  • 172
  • 11
  • okay thx i don´t know what to do – Motofo20 Aug 17 '23 at 08:21
  • As said before, `Intents` does not exist in the discord.js API so you can either replace it with `IntentsBitField` or `GatewayIntentBits`. `IntentsBitField` is a direct replacement and `GatewayIntentBits` seems to be a recent addition in discord.js but will need some code modification. – Daxelarne Aug 17 '23 at 08:25
  • is that right? 'const { Client, BitField, MessageEmbed } = require('discord.js'); const client = new Client({ intents: [ BitField.FLAGS.GUILDS, BitField.FLAGS.GUILD_MESSAGES ] });' – Motofo20 Aug 17 '23 at 08:31
  • If it work I want to say yes but I don't know where you find `BitField` as I didn't mention it in my message. – Daxelarne Aug 17 '23 at 08:33
  • thx i was stupid it works now – Motofo20 Aug 17 '23 at 08:46
  • Oh, I undestand, you kept only the part after Intents. Glad I was able to help you. If this is the answer you needed, please mark it as so. – Daxelarne Aug 17 '23 at 08:48