discord.py缺少权限,但bot是管理员

piv4azn7  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(422)

在编写一个机器人程序时,我遇到了一个错误,该程序应该禁止不和谐公会中的所有人(出于教育目的)。错误显示:

@bot.command(aliases=["ban"])
async def ban(ctx, reason="No reason ig"):
    for Member in list(ctx.guild.members):
           await Member.ban(reason=reason)
           await Member.send("You have been banned)
           print(f'[+] The User going under the name of {Member} has been banned')

现在;这很奇怪,因为bot有管理员权限,它的角色比其他任何人都高。它还启用了特权网关意图。还有一点需要说明的是,当我尝试创建角色或删除角色时,这是有效的。提前感谢您的帮助!

xkftehaa

xkftehaa1#

即使bot是admin,它也不能禁止角色更高的人,如果它的角色是最高的,它仍然不能禁止所有者,因此:

for Member in ctx.guild.members:
  try:
     try: # if a user has dms blocked this will stop the code with an error
        await Member.send("You have been banned")
     except:
        pass

     await Member.ban(reason=reason)

     print(f'[+] The User going under the name of {Member} has been banned')

  except:
     print(f'[!] couldn\'t ban {str(Member)}')

相关问题