mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
"""
|
|
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))
|