问题
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