[英]Discord.py Id to member
I have a list of id's and I want to get the list of members.我有一个 id 列表,我想获取成员列表。 how can I do it?
我该怎么做? i did try this
我确实试过这个
id_list=[]
for i in amounts :
if amounts[i] == 0 :
id_list.append(i)
for id in id_list:
members = [discord.utils.get(bot.get_all_members(), id=id) for id in id_list]
for member in members :
await remove(member , mover ) #probleme here mover is a role
async def remove( member: discord.Member, role: discord.Role):
await member.remove_roles(role)
Your question is different from the code that you've given.您的问题与您提供的代码不同。 To get a specific member, you can do:
要获取特定成员,您可以执行以下操作:
member = discord.utils.get(bot.get_all_members(), id=MEMBER_ID_HERE)
Or if you have the list of IDs:或者,如果您有 ID 列表:
id_list = [112233445566778899, 224466881133557799 # etc...
members = [m for m in bot.get_all_members() if m.id in id_list]
Post-edit:后期编辑:
You're able to get all members in a guild that don't have a specific role, and remove the role like this:您可以让公会中没有特定角色的所有成员,并像这样删除角色:
@bot.command()
async def remove(ctx, role: discord.Role):
members = [m for m in ctx.guild.members if role in m.roles]
for m in members:
await m.remove_roles(role)
await ctx.send(f"Successfully removed {role.mention} from all users!")
Calling another async function from a command:从命令调用另一个异步 function:
async def remove(role: discord.Role):
id_list = [112233445566778899, 224466881133557799 # etc...
members = [m for m in bot.get_all_members() if m.id in id_list]
for m in members:
await m.remove_roles(role)
@bot.command()
async def cmd(ctx, role: discord.Role = None):
if not role:
role = discord.utils.get(ctx.guild.roles, id=112233445566778899)
await remove(role) # you can also pass ctx if you need it in the function
References:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.