Files
Syntrel/cogs/moderation/kick.py

72 lines
2.5 KiB
Python
Raw Normal View History

2025-09-14 18:54:56 -04:00
"""
Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn (https://krypton.ninja)
Description:
🐍 A simple template to start to code your own and personalized Discord bot in Python
Version: 6.4.0
"""
import discord
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
class Kick(commands.Cog, name="kick"):
def __init__(self, bot) -> None:
self.bot = bot
@commands.hybrid_command(
name="kick",
description="Kick a user out of the server.",
)
@commands.has_permissions(kick_members=True)
@commands.bot_has_permissions(kick_members=True)
@app_commands.describe(
user="The user that should be kicked.",
reason="The reason why the user should be kicked.",
)
async def kick(
self, context: Context, user: discord.User, *, reason: str = "Not specified"
) -> None:
"""
Kick a user out of the server.
:param context: The hybrid command context.
:param user: The user that should be kicked from the server.
:param reason: The reason for the kick. Default is "Not specified".
"""
member = context.guild.get_member(user.id) or await context.guild.fetch_member(
user.id
)
if member.guild_permissions.administrator:
embed = discord.Embed(
description="User has administrator permissions.", color=0xE02B2B
)
await context.send(embed=embed)
else:
try:
embed = discord.Embed(
description=f"**{member}** was kicked by **{context.author}**!",
color=0xBEBEFE,
)
embed.add_field(name="Reason:", value=reason)
await context.send(embed=embed)
try:
await member.send(
f"You were kicked by **{context.author}** from **{context.guild.name}**!\nReason: {reason}"
)
except:
pass
await member.kick(reason=reason)
except:
embed = discord.Embed(
description="An error occurred while trying to kick the user. Make sure my role is above the role of the user you want to kick.",
color=0xE02B2B,
)
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Kick(bot))