Discord 角色的在线用户数 [英] Online User count from a Discord Role

查看:15
本文介绍了Discord 角色的在线用户数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 Discord 机器人将角色的在线用户数显示为活动.
我似乎无法弄清楚,我在网上找不到任何东西.
谁能给我示例代码或向我解释一下?

I want my Discord Bot to display the Number of Online Users of a Role as an Activity.
I can't seem to figure it out and i can't find anything on the Web.
Can someone give me example code or explain it to me?

推荐答案

你可以使用Guild.members.forEach() 循环遍历公会的每个成员,然后如果他们具有该角色(您可以使用 GuildMember.roles.has(Role.id) 检查)增加一个计数器.完成成员循环后,使用 Client.user.setActivity().
这就是你得到你想要的东西所需要的.

You can use Guild.members.forEach() to loop through every member of the guild, then if they have that role (you can use GuildMember.roles.has(Role.id) to check that) increase a counter. When you have finished your loop through the members, use the counter in your Client.user.setActivity().
That is what you need in order to get what you want.

试试这个东西,如果你仍然有问题发布 MCVE 我们会帮助你,但首先你需要尝试自己.

Try this stuff, if you still have problems post a MCVE and we'll help you, but first you need to try yourself.

这篇关于Discord 角色的在线用户数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆