简体   繁体   English

为什么我会收到这些错误? discord.js

[英]Why do I get these errors? discord.js

this is my code for a member counter in my server这是我的服务器中会员计数器的代码

module.exports = (client) => {
  const channelId = '818930375501152314'

  const updateMembers = (guild) => {
    const channel = guild.channels.cache.get(channelId)
    channel.setName(`Members: ${guild.memberCount.toLocaleString()}`)
  }

  client.on('guildMemberAdd', (member) => updateMembers(member.guild))
  client.on('guildMemberRemove', (member) => updateMembers(member.guild))

  const guild = client.guilds.cache.get('818930375488962611')
  updateMembers(guild)
}

and it has worked absolutely fine until today when I got this error out of no where, I uninstalled some packages too and that could've been a reason for this to happen but I reinstalled it and it is still like this它一直工作得很好,直到今天我不知从哪里得到这个错误,我也卸载了一些软件包,这可能是发生这种情况的原因,但我重新安装了它,它仍然是这样

edit: yes I saw that the channels was not in lowercase and fixed that, but it's still not working and i've done troubleshooting for almost an hour now and searched it up and its still not working, still get this problem编辑:是的,我看到频道不是小写并修复了它,但它仍然无法正常工作,我已经完成了近一个小时的故障排除并搜索它仍然无法正常工作,仍然遇到这个问题


c:\Users\myname\visual studio\bot\Cloud-hosted-bot\member-count.js:5
    const channel = guild.channels.cache.get(channelId)
                          ^

TypeError: Cannot read property 'channels' of undefined
    at updateMembers (c:\Users\myname\visual studio\bot\Cloud-hosted-bot\member-count.js:5:27)
    at module.exports (c:\Users\myname\visual studio\bot\Cloud-hosted-bot\member-count.js:13:3)
    at Object.<anonymous> (c:\Users\myname\visual studio\bot\Cloud-hosted-bot\bot.js:36:3)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

I'm new here to so sorry If I dont explain things to well, very glad you guys are helping me:)我是新来的,很抱歉如果我不能很好地解释事情,很高兴你们能帮助我:)

this is my code for a member counter in my server这是我的服务器中会员计数器的代码

module.exports = (client) => {
  const channelId = '818930375501152314'

  const updateMembers = (guild) => {
    const channel = guild.channels.cache.get(channelId)
    channel.setName(`Members: ${guild.memberCount.toLocaleString()}`)
  }

  client.on('guildMemberAdd', (member) => updateMembers(member.guild))
  client.on('guildMemberRemove', (member) => updateMembers(member.guild))

  const guild = client.guilds.cache.get('818930375488962611')
  updateMembers(guild)
}

and it has worked absolutely fine until today when I got this error out of no where, I uninstalled some packages too and that could've been a reason for this to happen but I reinstalled it and it is still like this它一直工作得很好,直到今天我不知从哪里得到这个错误,我也卸载了一些软件包,这可能是发生这种情况的原因,但我重新安装了它,它仍然是这样

edit: yes I saw that the channels was not in lowercase and fixed that, but it's still not working and i've done troubleshooting for almost an hour now and searched it up and its still not working, still get this problem编辑:是的,我看到频道不是小写并修复了它,但它仍然无法正常工作,我已经完成了近一个小时的故障排除并搜索它仍然无法正常工作,仍然遇到这个问题


c:\Users\myname\visual studio\bot\Cloud-hosted-bot\member-count.js:5
    const channel = guild.channels.cache.get(channelId)
                          ^

TypeError: Cannot read property 'channels' of undefined
    at updateMembers (c:\Users\myname\visual studio\bot\Cloud-hosted-bot\member-count.js:5:27)
    at module.exports (c:\Users\myname\visual studio\bot\Cloud-hosted-bot\member-count.js:13:3)
    at Object.<anonymous> (c:\Users\myname\visual studio\bot\Cloud-hosted-bot\bot.js:36:3)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

I'm new here to so sorry If I dont explain things to well, very glad you guys are helping me:)我是新来的,很抱歉如果我不能很好地解释事情,很高兴你们能帮助我:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM