简体   繁体   English

如何显示公会 discord.js 的机器人计数器

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

I want to make a bot counter in discord.js.我想在 discord.js 中制作一个机器人计数器。

For example when I type: " !bots ", the bot will send a message like: " There are 11 bots on this server "例如,当我输入:“ !bots ”时,机器人会发送如下消息:“此服务器上有 11 个机器人

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.您可以使用 members 属性上的 fetch() 方法来检索 Discord 服务器中所有成员的数组。 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在此处查看有关它的文档: 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.正如@Bqre 在下面的评论中所解释的那样,这可能并不理想。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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