Najmul190
Najmul190

Reputation: 21

How can I get my discord.js bots "Watching X Servers" status, to automatically update?

so im trying to get my bots status to automatically update, when it is added to a new server. The status currently, is "Watching Over 24 Servers", but for me to update the status, I have to restart the whole bot - is there a way to automatically do this? Here's the code:

  console.log('Ready!');
  client.user.setActivity(`${client.guilds.cache.size} Servers | ^help`, { type: 'WATCHING' })
      .then(presence => console.log(`Activity set to ${presence.activities[0].name} | ^help`))
      .catch(console.error);
})

Thanks.

Upvotes: 0

Views: 1932

Answers (1)

Nathn
Nathn

Reputation: 429

The setInterval method can refresh it every 60 seconds (Discord rate limit) :

client.on('ready', () => {
    setInterval(() => {
        client.user.setActivity(`${client.guilds.cache.size} Servers | ^help`, { type: 'WATCHING' })
    }, 60000); // Runs this every 60 seconds.
});

Upvotes: 1

Related Questions