import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='!')


@bot.event
async def on_ready():  # Creates an event that is called when the bot is connected to discord
    print('The bot is ready')


@bot.command()
@commands.has_permissions(ban_members=True)
async def unban(ctx, *, member):
    banned_users = await ctx.guild.bans()

    member_name, member_discriminator = member.split('#')
    for ban_entry in banned_users:
        user = ban_entry.user
        # The bot see the list of banned users and where the banned users and the tagged user's username and discriminator is
        if (user.name, user.discriminator) == (member_name, member_discriminator):
            # The bot see the list of banned users and where the banned users and the tagged user's username and discriminator is same, unban the tagged user
            await ctx.guild.unban(user)
            return await ctx.channel.send(f"Unbanned: {user.mention}")
    await ctx.send('User is not banned!')


@unban.error
async def _unban_error(ctx, error: commands.CommandError):
    if isinstance(error, commands.MissingPermissions):
        # Send error message, when ctx.author has not permission for ban members
        await ctx.reply('`Ban Members` permission is required to use this command!')
token = '<PASSWORD>'

bot.run(token)

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='!')


@bot.event
async def on_ready():  # Creates an event that is called when the bot is connected to discord
    print('The bot is ready')


@bot.command()
@commands.has_permissions(ban_members=True)
async def unban(ctx, *, member):
    banned_users = await ctx.guild.bans()

    member_name, member_discriminator = member.split('#')
    for ban_entry in banned_users:
        user = ban_entry.user
        # The bot see the list of banned users and where the banned users and the tagged user's username and discriminator is
        if (user.name, user.discriminator) == (member_name, member_discriminator):
            # The bot see the list of banned users and where the banned users and the tagged user's username and discriminator is same, unban the tagged user
            await ctx.guild.unban(user)
            return await ctx.channel.send(f"Unbanned: {user.mention}")
    await ctx.send('User is not banned!')


@unban.error
async def _unban_error(ctx, error: commands.CommandError):
    if isinstance(error, commands.MissingPermissions):
        # Send error message, when ctx.author has not permission for ban members
        await ctx.reply('`Ban Members` permission is required to use this command!')
token = '<PASSWORD>'

bot.run(token)

# Creates an event that is called when the bot is connected to discord # The bot see the list of banned users and where the banned users and the tagged user's username and discriminator is # The bot see the list of banned users and where the banned users and the tagged user's username and discriminator is same, unban the tagged user # Send error message, when ctx.author has not permission for ban members