无法读取discord.js v14上未定义的属性(读取’guilds’)。

huangapple go评论88阅读模式
英文:

Cannot read properties of undefined (reading 'guilds') on discord.js v14

问题

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 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?

答案1

得分: -1

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

自discord.js v14起,许多枚举类型的写法已从SCREAMING_SNAKE_CASE更改为PascalCase。此外,编写意图的方式已从Intents.FLAGS.XXX_YYY更改为GatewayIntentBits.XxxYyy

英文:

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.

huangapple
  • 本文由 发表于 2023年7月13日 14:54:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676659.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定