Python从特定角色获取所有成员列表 [英] Python get all members list from a specific role
本文介绍了Python从特定角色获取所有成员列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不和谐频道中使用!getuser
命令从特定角色获取成员列表。
How to get a members list from a specific role with !getuser
command in discord channel.
@bot.command(pass_context=True)
async def getuser(ctx):
机器人使用其ID回复
1. @user1#123
2. @user2#123
推荐答案
rewrite分支提供属性 Role.members
。
The rewrite branch provides an attribute Role.members
.
在异步分支上,您必须遍历服务器的所有成员并检查其角色。
On the async branch, you'll have to loop through all the members of the server and check their roles.
@bot.command(pass_context=True)
async def getuser(ctx, role: discord.Role):
role = discord.utils.get(ctx.message.server.roles, name="mod")
if role is None:
await bot.say('There is no "mod" role on this server!')
return
empty = True
for member in ctx.message.server.members:
if role in member.roles:
await bot.say("{0.name}: {0.id}".format(member))
empty = False
if empty:
await bot.say("Nobody has the role {}".format(role.mention))
这篇关于Python从特定角色获取所有成员列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文