0

This is the code below. the keep alive is another part of code to keep my bot online 24/7.

import os
from keep_alive import keep_alive
from discord.ext import commands
import random
import requests
import json
import asyncio
client = commands.Bot(command_prefix='>')

@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, *, reason=None):
  await member.ban(reason=reason)
  embed=discord.Embed(title="Ban", description=f'User {member} has been banned!', color=0x00FFFF)
  await ctx.send(embed=embed)

keep_alive()

client.run(os.getenv('TOKEN'))
ColeTMK
  • 96
  • 1
  • 10
  • 1
    Because you have administrator permission, your bot have not ban members permissions and raising `discord.Forbidden` error. – Ali Hakan Kurt Apr 24 '21 at 16:36

2 Answers2

1

A permission error generally means that the bot doesn't have the permission to ban users. Since this works on your server we can conclude that the code is fine. You'll have to give it permission to ban users from the server itself by going to server setting > Roles > (Bot Role) Then turn this option on: ban image

Quessts
  • 440
  • 2
  • 19
0

It looks like you are setting up your bot without the proper intents for kicking/banning people. You can read about it here:

How do I get the discord.py intents to work?

A random coder
  • 453
  • 4
  • 13