Well today I’ll show you How To Create Kick Ban & Unban Command Using Discord.py, if you don’t know anything about discord.py then check this our previous post – Create Your First Discord Bot With Python.
Create Kick Ban & Unban Command Using Discord.py
first you will have to use
import discord from discord.ext import commands
then we will set prefix by using
client = commands.Bot(command_prefix = '!')
Now lets create kick command using discord.py
HOW TO CREATE KICK COMMAND USING DISCORD.PY
we will first use client.command and will set permissions which we need to execute that command
@client.command() @commands.has_permissions(kick_members=True)
now we will define kick command by using
async def kick(ctx, user: discord.Member, *, reason=None): await user.kick(reason=reason) await ctx.send(f"{user} have been kicked sucessfully")

wow! we have created kick command, its so simple
Full Codes of Kick Command
#kick command using discord.py @client.command() @commands.has_permissions(kick_members=True) async def kick(ctx, user: discord.Member, *, reason=None): await user.kick(reason=reason) await ctx.send(f"{user} have been kicked sucessfully") # <----- kick commmand end ------>
HOW TO MAKE BAN & UNBAN COMMAND USING DISCORD.PY
we will have to do the same thing as we did in ban command.
@client.command() @commands.has_permissions(ban_members=True) async def ban(ctx, user: discord.Member, *, reason=None): await user.ban(reason=reason) await ctx.send(f"{user} have been bannned sucessfully")
just change permissions from kick_members to ban_members.

Now lets make unban command
@client.command() 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 if (user.name, user.discriminator) == (member_name, member_discriminator): await ctx.guild.unban(user) await ctx.send(f"{user} have been unbanned sucessfully") return

Watch Our Video Tutorial –
For Any Support Join Our Discord Server – https://discord.gg/qQN7YdE