Why does client.guilds.cache.size only say “0” in my playing status even if it's in 2 servers?

别说谁变了你拦得住时间么 提交于 2021-02-05 09:27:09

问题


i have seen many people who had trouble with client.guilds.size but I switched to the recently suggested client.guilds.cache.size. In my playing status, it only says "WATCHING my prefix | 0 servers." same happens for trying to fetch the member count and channel count.

let activities = [ `${client.guilds.cache.size} servers`, `${client.channels.cache.size} channels`, `${client.users.cache.size} users` ], i = 0;

setInterval(() => client.user.setActivity(`${prefix}help | ${activities[i ++ % activities.length]}`, { type: "WATCHING"}),`${process.env.INTERVAL}`)

This is the script I am using to achieve that. I already have an Eval command, that returns 2 aswell.

I can't seem to find a solution to this somehow. I hope you can help me, if you need anything, tell me!


回答1:


Your issue is that your client has not logged in before you grab the guilds collection

You need to place that code inside your ready event.

client.on('ready', () => {
  let activities = [ `${client.guilds.cache.size} servers`, `${client.channels.cache.size} channels`, `${client.users.cache.size} users` ], i = 0;

  setInterval(() => client.user.setActivity(`${prefix}help | ${activities[i ++ % activities.length]}`, { type: "WATCHING"}),`${process.env.INTERVAL}`)
})


来源:https://stackoverflow.com/questions/61980179/why-does-client-guilds-cache-size-only-say-0-in-my-playing-status-even-if-its

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!