【问题标题】:discord.py missing permissions but the bot is an administratordiscord.py 缺少权限,但机器人是管理员
【发布时间】:2021-07-27 18:04:32
【问题描述】:

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

@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 有管理员权限,它的角色比任何人都高。它还启用了特权网关意图。还应该说明的一件事是,当我尝试创建角色或删除它们时,这是可行的。提前感谢您的帮助!

【问题讨论】:

  • 您无法向已被禁止的成员发送消息,请在禁止成员之前尝试发送成员消息,看看是否有帮助。

标签: python discord discord.py


【解决方案1】:

即使bot是admin,也不能ban更高角色的人,如果是最高角色,也不能ban owner,所以:

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
     
     try:
       await Member.ban(reason=reason)
     except: 
         pass
     
     print(f'[+] The User going under the name of {Member} has been banned')

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

【讨论】:

  • 它仍然以“无法禁止(我的机器人名称)”结束。我仍在努力寻找解决此问题的方法
  • 再添加一次尝试:except: on await Member.ban()
猜你喜欢
  • 2019-09-17
  • 2021-12-09
  • 2021-08-12
  • 2020-12-02
  • 2019-03-06
  • 2020-10-03
  • 1970-01-01
  • 2021-02-14
  • 2014-04-18
相关资源
最近更新 更多