Discord.py-禁止服务器中的每个人都没有角色

时间:2020-03-18 23:36:15

标签: permissions bots discord discord.py

我当时正忙着使用ban every命令,试图对其进行修复,以便它实际上在执行某些操作而不是给我错误:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

问题是我不知道如何排除管理员角色并禁止没有角色的成员(只能与@everyone ping通)。我当前正在使用的代码:

@client.command()
async def e(ctx):
    print('Logged in!')
    for member in client.get_all_members():
        await member.ban(reason=banreason + banreason2 + banreason3)
        await ctx.send(f"**{member.display_name}** was banned and invite links were sent. :white_check_mark:")
        print(f"Banned {member.display_name} and invite links were sent.")
    print("Banning is complete!")

注意:banreason没有错误,它工作正常,并且与权限错误无关。 我还将该机器人置于了我要禁止的角色之上。

1 个答案:

答案 0 :(得分:1)

如果您只想排除除@everyone以外的所有角色,则可以使用以下内容。

@client.command()
async def e(ctx):
    for member in ctx.guild.members:
        if len(member.roles) < 2:
            await member.ban(reason=banreason + banreason2 + banreason3)
            await ctx.send(f"**{member.display_name}** was banned and invite links were sent. :white_check_mark:")
            print(f"Banned {member.display_name} and invite links were sent.")
    print("Banning complete!")