简体   繁体   中英

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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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