Reputation: 35
I made a simple discord verify bot, but I want to make the bot status to watching # people verifying (the # is how many people in my server). I see some bots have it, but I don't know how to make it. Here is my current code for the bot status:
if (Object.keys(this.config.presence).length !== 0) {
this.user.setPresence({
game: {
name: this.config.presence.name,
type: this.config.presence.type
},
status: "online"
}).catch(console.error);
}
Upvotes: 0
Views: 12732
Reputation: 1
its as simple as:
bot.user.setPresence({ activity: { name: `${bot.users.cache.size} members` , type: 'WATCHING'}, status: 'online' })
Upvotes: 0
Reputation: 2722
At the first you need set interval command to update member.
You dont need use this.user
for this operation. The previus answer method will display only cached users, so its wrong way, because on bot start, you will has no users in this collection.
If you need display members on your own server you can do like this:
guild.memberCount
client.on('ready', () => {
setInterval(() => {
targetGuild = client.guilds.get('GUILD ID HERE')
if(targetGuild) {
client.user.setPresence({ game: { name: targetGuild.memberCount + ' people verifying!', type: 'WATCHING' }, status: 'online' })
.then(console.log)
.catch(console.error);
}
}, 1000 * 60 * 5);
});
After bot start, this will update after 5 minutes.
For test you can change
}, 1000 * 60 * 5)
to}, 1000);
Upvotes: 1
Reputation: 11
Welcome to StackOverflow!
client.users.size
should return you all the users from all the guilds that the bot is into!
if (Object.keys(this.config.presence).length !== 0) {
this.user.setPresence({
game: {
name: client.users.size + ' people verifying!',
type: this.config.presence.type
},
status: "online"
}).catch(console.error);
}
You can also find this at discord.js documentation.
Upvotes: 0