简体   繁体   English

为什么client.guilds.cache.size在我的播放状态中只显示“0”,即使它在2个服务器中?

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

i have seen many people who had trouble with client.guilds.size but I switched to the recently suggested client.guilds.cache.size .我见过很多人对client.guilds.size有问题,但我改用了最近建议的client.guilds.cache.size In my playing status, it only says "WATCHING my prefix | 0 servers."在我的播放状态中,它只显示"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.我已经有一个 Eval 命令,它也返回 2。

I can't seem to find a solution to this somehow.我似乎无法以某种方式找到解决方案。 I hope you can help me, if you need anything, tell me!我希望你能帮助我,如果你需要什么,请告诉我!

Your issue is that your client has not logged in before you grab the guilds collection您的问题是您的client在您获取guilds收藏之前尚未登录

You need to place that code inside your ready event.您需要将该代码放在您的ready事件中。

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}`)
})

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

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