-2

I am using discord.js 14.11.0 and I am having trouble to understand how to fix the error.

index.js:

const Discord = require('discord.js');
const { Client, MessageEmbed, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.FLAGS.GUILDS, GatewayIntentBits.FLAGS.GUILD_MESSAGES, GatewayIntentBits.FLAGS.GUILD_MEMBERS] });
require('dotenv').config();


client.on('ready', () => {
    console.log(`${client.user.tag} olarak giriş yaptiniz!`);
});

client.on('messageCreate', async (message) => {
if(message.content == '!massiveunban') {
const guild = client.guilds.cache.get('Cencored');
try { 

    guild.bans.fetch().then(async (i) => {
        const ids = i.map((u) => u.user.id);
          ids.forEach(async (id) => {
            await guild.members.unban(id, 'Temizlik').then(async (u) => {
                console.log(`Engeli acildi: ${u.tag}`);
            });
        })
    })

} catch (error) {
    console.error(error);
}

}});

client.login(process.env.TOKEN);

const client = new Client({ intents: [GatewayIntentBits.FLAGS.GUILDS, GatewayIntentBits.FLAGS.GUILD_MESSAGES, GatewayIntentBits.FLAGS.GUILD_MEMBERS] }); ^

TypeError: Cannot read properties of undefined (reading 'GUILDS')

I guess its around here but I couldn't find the problem. Could you please help me to understand where is the problem?

Muto
  • 1
  • 3
  • There is no such thing as `GatewayIntentBits.FLAGS.GUILDS`. It should be `GatewayIntentBits.Guilds`. The same with the other two. Read this related question and answer: https://stackoverflow.com/a/73028855/6126373 – Zsolt Meszaros Jul 13 '23 at 07:34
  • You'll also have problems with `message.content` being empty. So read this answer too: https://stackoverflow.com/a/73037243/6126373 – Zsolt Meszaros Jul 13 '23 at 07:37
  • And after that, you can also read this: https://stackoverflow.com/q/37576685/6126373 – Zsolt Meszaros Jul 13 '23 at 07:37

1 Answers1

-1

answer:

const { Client, MessageEmbed, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] });

Starting with discord.js v14, the writing style for many enumerated types has changed from SCREAMING_SNAKE_CASE to PascalCase. Also, the way to write intents has changed from Intents.FLAGS.XXX_YYY to GatewayIntentBits.XxxYyy.

waki285
  • 338
  • 1
  • 11