简体   繁体   中英

how to show the bot counter for a guild discord.js

I want to make a bot counter in discord.js.

For example when I type: " !bots ", the bot will send a message like: " There are 11 bots on this server "

I previously tried this code, but it seams to give me just the number of bots that are in cache, not all of them:

message.guild.members.cache.filter(member => member.user.bot).size

You can use the fetch() method on the members property to retrieve an array of all the members in the Discord server. You can then filter or otherwise loop through the array to check if a member is a bot.

Check the docs about it here: https://discord.js.org/#/docs/main/stable/class/GuildMemberManager?scrollTo=fetch

As explained by @Bqre in the comment below, this is probably not ideal though.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM