Reputation: 27
I have a discord bot where its activity is set like below
module.exports = (client) => {
console.log(`${client.user.username} ✅`)
const activities = [
`Music Videos`,
`*help`,
`In ${client.guilds.cache.size} Servers`,
`Support Server ====> discord.gg/ZJevrUQ46Q`
];
let i = 0;
setInterval(() => client.user.setActivity(`${activities[i++ % activities.length]}`, { type: 'PLAYING' }), 5000);
}
Is there any way for me to update its server count when it's added to a new server?
Thanks in advance!
Upvotes: 2
Views: 219
Reputation: 1196
Using a Client#guildCreate
event would make this more convenient to achieve. The event would only emit whenever a client joins a guild, whether it's created its own, or gets invited onto a server.
This should work:
client.on('guildCreate', guild => {
const activities = [
`Music Videos`,
`*help`,
`In ${client.guilds.cache.size} Servers`,
`Support Server ====> discord.gg/ZJevrUQ46Q`,
`Most recently added to ${guild.name}` //a nice bonus feature!
];
let i = 0;
setInterval(() => client.user.setActivity(`${activities[i++ % activities.length]}`, { type: 'PLAYING' }), 5000);
});
Upvotes: 2