[英]How do I get all members with a certain role discord.py
I have my command .roleinactivity @whatever role
.我有我的命令.roleinactivity @whatever role
。 How do I take whatever role that was pinged and find all of the members that have that role?我如何采取任何被 ping 过的角色并找到所有具有该角色的成员?
I've been trying to loop through each member in the server with an if statement to see if they have said role but it didn't work.我一直在尝试使用 if 语句遍历服务器中的每个成员,以查看他们是否说过角色,但它不起作用。 Can anyone point me in the right direction?谁能指出我正确的方向?
You can get all the users with your role by using .members
:您可以使用.members
获取具有您角色的所有用户:
@client.command()
async def roleinactivity(ctx, role : discord.Role):
print(role.members)
role: discord.Role
- transforms your role argument to discord.Role
object to make it work properly. role: discord.Role
- 将您的角色参数转换为discord.Role
object 以使其正常工作。 Otherwise, it would get recognized as string
.否则,它将被识别为string
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.