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

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

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

问题

index.js

  1. const Discord = require('discord.js');
  2. const { Client, MessageEmbed, GatewayIntentBits } = require('discord.js');
  3. const client = new Client({ intents: [GatewayIntentBits.FLAGS.GUILDS, GatewayIntentBits.FLAGS.GUILD_MESSAGES, GatewayIntentBits.FLAGS.GUILD_MEMBERS] });
  4. require('dotenv').config();
  5. client.on('ready', () => {
  6. console.log(`${client.user.tag} olarak giriş yaptiniz!`);
  7. });
  8. client.on('messageCreate', async (message) => {
  9. if (message.content == '!massiveunban') {
  10. const guild = client.guilds.cache.get('Cencored');
  11. try {
  12. guild.bans.fetch().then(async (i) => {
  13. const ids = i.map((u) => u.user.id);
  14. ids.forEach(async (id) => {
  15. await guild.members.unban(id, 'Temizlik').then(async (u) => {
  16. console.log(`Engeli acildi: ${u.tag}`);
  17. });
  18. })
  19. })
  20. } catch (error) {
  21. console.error(error);
  22. }
  23. }
  24. });
  25. 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:

  1. const Discord = require('discord.js');
  2. const { Client, MessageEmbed, GatewayIntentBits } = require('discord.js');
  3. const client = new Client({ intents: [GatewayIntentBits.FLAGS.GUILDS, GatewayIntentBits.FLAGS.GUILD_MESSAGES, GatewayIntentBits.FLAGS.GUILD_MEMBERS] });
  4. require('dotenv').config();
  5. client.on('ready', () => {
  6. console.log(`${client.user.tag} olarak giriş yaptiniz!`);
  7. });
  8. client.on('messageCreate', async (message) => {
  9. if(message.content == '!massiveunban') {
  10. const guild = client.guilds.cache.get('Cencored');
  11. try {
  12. guild.bans.fetch().then(async (i) => {
  13. const ids = i.map((u) => u.user.id);
  14. ids.forEach(async (id) => {
  15. await guild.members.unban(id, 'Temizlik').then(async (u) => {
  16. console.log(`Engeli acildi: ${u.tag}`);
  17. });
  18. })
  19. })
  20. } catch (error) {
  21. console.error(error);
  22. }
  23. }});
  24. 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

  1. const { Client, MessageEmbed, GatewayIntentBits } = require('discord.js');
  2. 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:

  1. const { Client, MessageEmbed, GatewayIntentBits } = require('discord.js');
  2. 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:

确定