0

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!

feba
  • 1
  • 1
  • 1
  • Where do you have this code snippet? – Syntle May 24 '20 at 00:35
  • Do you update `activities` each time, or it is only set at the start of the program? – theusaf May 24 '20 at 00:36
  • @Syntle i tried multiple locations, but the `let activities` is at the top, where all the consts are and the `setInterval()` comes directly after. – feba May 24 '20 at 00:51
  • @theusaf its only set at the start of the program... how do i update that then? – feba May 24 '20 at 00:52
  • You can use `activities = [ \`${client.guilds.cache.size} servers\`, \`${client.channels.cache.size} channels\`, \`${client.users.cache.size} users\` ]` in the interval function, or put it on a separate interval. Basically, just keep getting the cache when you change your status. – theusaf May 24 '20 at 16:02

1 Answers1

3

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}`)
})
Syntle
  • 5,168
  • 3
  • 13
  • 34
  • Thanks, that worked! I combined the suggestion of you and theusaf to make it work now! Thank you. – feba May 24 '20 at 21:19