简体   繁体   English

Discord 踢所有人的机器人只踢没有角色的人

[英]Discord bot that kicks everyone only kicks people without roles

Hello I was making a discord bot that kicks everyone in group but the only problem is that it only kicks members without any role.您好,我正在制作一个 discord 机器人,它会踢组中的每个人,但唯一的问题是它只会踢没有任何角色的成员。 If someone could give me a boost because I'm learning discord py slowly.如果有人可以给我一个提振,因为我正在慢慢学习 discord py。

Code:代码:

@client.command(pass_context=True)
async def free(ctx):
    guild=ctx.message.guild
    for member in tuple(guild.members):
        try:
            await member.kick()
        except:
            continue

Remove the try except .删除try except It displays you the error why it cannot kick a Discord member.它会向您显示为什么它无法踢出 Discord 成员的错误。 My guess is that the member the bot tried to kick is higher in hierarchy and these people the bot cannot kick.我的猜测是,机器人试图踢的成员等级更高,而机器人无法踢这些人。

https://support.discord.com/hc/en-us/articles/214836687-Role-Management-101 https://support.discord.com/hc/en-us/articles/214836687-Role-Management-101

Additional to the role sorting hierarchy, there's a special exception placed on banning, kicking, and nicknaming members: Even if users have ban/kick/nickname permissions, they cannot ban / kick / change nicknames of anyone with the same role or a role higher than theirs.除了角色排序层次结构之外,对成员进行封禁、踢出和昵称还有一个特殊的例外:即使用户具有封禁/踢出/昵称权限,他们也不能禁止/踢出/更改具有相同角色或更高角色的任何人的昵称比他们的。

Make sure your bot's role is higher than all of them.确保您的机器人的角色高于所有这些。

@client.command(pass_context=True)
    async def free(ctx):
        members = ctx.guild.members
        for member in members:
            await member.kick()

You do not need the try except and tuple.你不需要 try except 和 tuple。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM