Answers for "how to make a kick command discord.py"

0

how to kick and ban members with discord.py

#this was in a cog   
# The below code bans player.
@commands.command()
@commands.has_permissions(ban_members=True)
  async def ban(self, ctx, member: discord.Member, *, reason=None):
     await member.ban(reason=reason)
     await ctx.send(f'User {member} has been kick')

# The below code unbans player.
@commands.command()
@commands.has_permissions(administrator=True)
  async def unban(self, 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'Unbanned {user.mention}')
                return

# The below code kicks player
@commands.command()
@commands.has_permissions(kick_members=True)
    async def kick(self, ctx, member: discord.Member, *, reason=None):
        await member.kick(reason=reason)
        await ctx.send(f'User {member} has been kick')
Posted by: Guest on June-24-2020
1

discord.py kick and ban command

import asyncio
import random
from asyncio.windows_events import NULL
import discord
from discord.embeds import Embed
from discord.ext import commands
from discord.ext.commands import has_permissions
from discord.ext.commands import has_permissions, CheckFailure
from discord.ext.commands import has_permissions, MissingPermissions
import os
import time
import typing
from discord.ext import commands, tasks
from discord.errors import Forbidden
from discord.ext.commands.bot import Bot



@bot.command()
@has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, *, reason=None):
    username_1 = ctx.message.author.name
    avatar_1 = ctx.message.author.avatar_url
    await member.ban(reason=reason)
    embed=discord.Embed(title=f'User {member} has been kick')
    embed.set_author(name=f"requested by {username_1}", icon_url=avatar_1)
    await ctx.send(embed=embed)


@bot.command()
@has_permissions(administrator=True)
async def unban(ctx, *, member):
    username_1 = ctx.message.author.name
    avatar_1 = ctx.message.author.avatar_url
    
    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)
            embed=discord.Embed(title=f'Unbanned {user.mention}')
            embed.set_author(name=f"requested by {username_1}", icon_url=avatar_1)
            await ctx.send(embed=embed)
            return


@bot.command()
@has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
    username_1 = ctx.message.author.name
    avatar_1 = ctx.message.author.avatar_url
    await member.kick(reason=reason)
    embed=discord.Embed(title=f'User {member} has been kick')
    embed.set_author(name=f"requested by {username_1}", icon_url=avatar_1)
    await ctx.send(embed=embed)
Posted by: Guest on September-12-2021
-1

kick member discord py

# Might Work...
@bot.command(pass_context = True)
async def kick(ctx, userName: discord.User):
    await bot.kick(userName)
Posted by: Guest on August-29-2020

Code answers related to "how to make a kick command discord.py"

Python Answers by Framework

Browse Popular Code Answers by Language