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