英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论