user12984498
user12984498

Reputation:

discord.py missing permissions but the bot is an administrator

While coding a bot that is supposed to ban everyone in a discord guild (For educational purposes), I have encountered an error. The error says:

@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')

Now; This is very weird, because the Bot has administrator permissions, it's role is higher than anyone else's. It also has the Priviliged Gateaway Intents enabled. One thing that should also be stated is that when I attempt to create roles or delete them, that works. Thanks in advance for your help!

Upvotes: 1

Views: 1262

Answers (2)

Gamercoder
Gamercoder

Reputation: 1

You may be missing intents. To enable intents go over here.

Bot entry in menu

  1. Go into your app portal, and click Bot

  2. Enable all intents:

Intents to enable

  1. And insert this code before client.run:
 intents = discord.Intents.default()
 intents.typing = True
 intents.presences = True
 intents.message_content = True

Intents documentation

Upvotes: 0

ssebastianoo
ssebastianoo

Reputation: 44

even if the bot is admin, it can't ban people with higher roles, and if its role is the highest one, it still can't ban the owner, so:

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)}')

Upvotes: 1

Related Questions