1@commands.command() # uses command decorators, in this case inside a cog
2@commands.has_permissions(ban_members=True) # only people that have permissions to ban users can use this command
3async def ban(self, ctx, user: discord.Member, *, reason): # The person banning someone has to ping the user to ban, and input a reason. Remove self if you are outside a cog.
4 await ctx.guild.ban(user, reason=reason) # Bans the user.
5 await user.send(f"You have been banned in {ctx.guild} for {reason}") # Private messages user.
6 await ctx.send(f"{user} has been successfully banned.") # messages channel to tell everyone it worked
1#this was in a cog
2# The below code bans player.
3@commands.command()
4@commands.has_permissions(ban_members=True)
5 async def ban(self, ctx, member: discord.Member, *, reason=None):
6 await member.ban(reason=reason)
7 await ctx.send(f'User {member} has been kick')
8
9# The below code unbans player.
10@commands.command()
11@commands.has_permissions(administrator=True)
12 async def unban(self, ctx, *, member):
13 banned_users = await ctx.guild.bans()
14 member_name, member_discriminator = member.split("#")
15
16 for ban_entry in banned_users:
17 user = ban_entry.user
18
19 if (user.name, user.discriminator) == (member_name, member_discriminator):
20 await ctx.guild.unban(user)
21 await ctx.send(f'Unbanned {user.mention}')
22 return
23
24# The below code kicks player
25@commands.command()
26@commands.has_permissions(kick_members=True)
27 async def kick(self, ctx, member: discord.Member, *, reason=None):
28 await member.kick(reason=reason)
29 await ctx.send(f'User {member} has been kick')