不和谐角色的在线用户数

不和谐角色的在线用户数

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

问题描述

我希望Discord Bot将某个角色的在线用户数显示为活动.
我似乎无法弄清楚,在网上也找不到任何东西.
有人可以给我示例代码或向我解释吗?

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.

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

08-21 14:52