Answers for "how to kick and ban members with 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
0

how to kick and ban members with discord.py

@client.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
    if reason==None:
      reason=" no reason provided"
    await ctx.guild.kick(member)
    await ctx.send(f'User {member.mention} has been kicked for {reason}')
Posted by: Guest on July-09-2021

Code answers related to "how to kick and ban members with discord.py"

Python Answers by Framework

Browse Popular Code Answers by Language