discord py kick and ban command

Solutions on MaxInterview for discord py kick and ban command by the best coders in the world

showing results for - "discord py kick and ban command"
Pip
08 Feb 2016
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')
Samuel
13 Jul 2017
1import asyncio
2import random
3from asyncio.windows_events import NULL
4import discord
5from discord.embeds import Embed
6from discord.ext import commands
7from discord.ext.commands import has_permissions
8from discord.ext.commands import has_permissions, CheckFailure
9from discord.ext.commands import has_permissions, MissingPermissions
10import os
11import time
12import typing
13from discord.ext import commands, tasks
14from discord.errors import Forbidden
15from discord.ext.commands.bot import Bot
16
17
18
19@bot.command()
20@has_permissions(ban_members=True)
21async def ban(ctx, member: discord.Member, *, reason=None):
22    username_1 = ctx.message.author.name
23    avatar_1 = ctx.message.author.avatar_url
24    await member.ban(reason=reason)
25    embed=discord.Embed(title=f'User {member} has been kick')
26    embed.set_author(name=f"requested by {username_1}", icon_url=avatar_1)
27    await ctx.send(embed=embed)
28
29
30@bot.command()
31@has_permissions(administrator=True)
32async def unban(ctx, *, member):
33    username_1 = ctx.message.author.name
34    avatar_1 = ctx.message.author.avatar_url
35    
36    banned_users = await ctx.guild.bans()
37    member_name, member_discriminator = member.split("#")
38    
39    for ban_entry in banned_users:
40        user = ban_entry.user
41
42        if (user.name, user.discriminator) == (member_name, member_discriminator):
43            await ctx.guild.unban(user)
44            embed=discord.Embed(title=f'Unbanned {user.mention}')
45            embed.set_author(name=f"requested by {username_1}", icon_url=avatar_1)
46            await ctx.send(embed=embed)
47            return
48
49
50@bot.command()
51@has_permissions(kick_members=True)
52async def kick(ctx, member: discord.Member, *, reason=None):
53    username_1 = ctx.message.author.name
54    avatar_1 = ctx.message.author.avatar_url
55    await member.kick(reason=reason)
56    embed=discord.Embed(title=f'User {member} has been kick')
57    embed.set_author(name=f"requested by {username_1}", icon_url=avatar_1)
58    await ctx.send(embed=embed)
queries leading to this page
discord py ban members with idhow to ban in discord pypython ban discord commandspython discord how to kick userban with discord pydiscord py kick membersdiscord py kickablediscord py kick and ban commanddiscord py kick and ban commandkick function discord py pythonhow to have a bot ban people on discord pydiscord bot ban and kick command pythonkick 2f ban discord bot pythondiscord py kick from discorddiscord py ban membersban member discord pyban command discord pykick ban expection discord bot pythonbot command to kick people in discord pydiscord py ban comand kick log discord pyban discord bot pythondiscord py ban all membersban members discord pydiscord py ban commandkick code discord pyhow to kick member discord pyuser kick reason discord pycommand kick bot discord pythondiscord py working ban commandban discord pykick discord pypython discord ban usedpython ban command discordhow to kick members with bot discord pydiscord py bandiscord python kick commandban command discord pykick discord pythondiscord python ban commandkick in discord pydiscord discord bot ban and kick code pythonhow to kick and ban people in discord pydiscord py how to banhow to make a kick ban command discord pydiscord py ban on bot eventpython discord bot kick with iddiscord py ban from eventban and kick not working discord pyban everyone discord pyhow ot ban discord pydiscord py ban usercommand for kick disocrd 2cpyon kicked 2fbanned from guild discord pymaking ban in discord pypython member ban discord pydiscord bot python kick commandhow to make a ban and kick command discord pypython discord how to give kick reasondiscord py kick function doesn 27t workkick ban discord pypython discord bot kick memberkick 26 ban discord pyhow to ban a player discord pydiscord py ban user from messageban command discord pykick command discord pyban command dm embed discord pypython discord bot kick commandhow to make a kick command discord pyban members discord pyhow to make kick and ban command in discord pyban user in discord pydiscord py ban codekick members discord pyhow to create a ban command on discord pyreasons discord pyhow to make a ban command discord pyban discord pydiscord py ban memberhow to get all bans discord pyhow to kick and ban people in disocrd pyhow to make a ban script discord bot pyhow to make a kick command in discord pykick member from server discord pykick function discord pyhow to kick a player discord bot pydiscord py kick codehow to kick people discord pykick discord py rewritediscord py kick and ban commandshow to ban in discord using discord pymember ban discord pyban kick and ban users discord pykick member discord py kick discord pydiscord py how to banpython discord py kick memberpython ban function discordhow to kick someone with discord pyhow to ban member discord pythondiscord py ban commandban players discord pydiscord py ban wordsdiscord ban and kick command discord pydiscord py kickhow to ban member discord pyhow to get bot kick reason discord pyhow to ban members in discord pyhow to add reason to discord bot commanddiscord py banpython discord ban commandkick and ban command discord pydiscord py kick memberban in discord pydiscord python banhow to block mass bans discord pyhow to make ban command discord pykick from server discord pyhow to make discord bot ban and kick with specific roles in discord pyon member kick discord pykick member discord pydiscord py reason kickdiscord py kick and banon kick discord pydiscord py how to say a message on a member bankick pythond discord bothow to kick using discord pyhow to kick someone for a message discord pythonget the user ban reason discord pyhow to kick and ban members with discord pydiscord py ban with iddiscord py kick and ban command