mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 19:50:12 +01:00
73 lines
2.5 KiB
Python
73 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 Ban(commands.Cog, name="ban"):
|
||
|
|
def __init__(self, bot) -> None:
|
||
|
|
self.bot = bot
|
||
|
|
|
||
|
|
@commands.hybrid_command(
|
||
|
|
name="ban",
|
||
|
|
description="Bans a user from the server.",
|
||
|
|
)
|
||
|
|
@commands.has_permissions(ban_members=True)
|
||
|
|
@commands.bot_has_permissions(ban_members=True)
|
||
|
|
@app_commands.describe(
|
||
|
|
user="The user that should be banned.",
|
||
|
|
reason="The reason why the user should be banned.",
|
||
|
|
)
|
||
|
|
async def ban(
|
||
|
|
self, context: Context, user: discord.User, *, reason: str = "Not specified"
|
||
|
|
) -> None:
|
||
|
|
"""
|
||
|
|
Bans a user from the server.
|
||
|
|
|
||
|
|
:param context: The hybrid command context.
|
||
|
|
:param user: The user that should be banned from the server.
|
||
|
|
:param reason: The reason for the ban. Default is "Not specified".
|
||
|
|
"""
|
||
|
|
member = context.guild.get_member(user.id) or await context.guild.fetch_member(
|
||
|
|
user.id
|
||
|
|
)
|
||
|
|
try:
|
||
|
|
if member.guild_permissions.administrator:
|
||
|
|
embed = discord.Embed(
|
||
|
|
description="User has administrator permissions.", color=0xE02B2B
|
||
|
|
)
|
||
|
|
await context.send(embed=embed)
|
||
|
|
else:
|
||
|
|
embed = discord.Embed(
|
||
|
|
description=f"**{member}** was banned by **{context.author}**!",
|
||
|
|
color=0xBEBEFE,
|
||
|
|
)
|
||
|
|
embed.add_field(name="Reason:", value=reason)
|
||
|
|
await context.send(embed=embed)
|
||
|
|
try:
|
||
|
|
await member.send(
|
||
|
|
f"You were banned by **{context.author}** from **{context.guild.name}**!\nReason: {reason}"
|
||
|
|
)
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
await member.ban(reason=reason)
|
||
|
|
except:
|
||
|
|
embed = discord.Embed(
|
||
|
|
title="Error!",
|
||
|
|
description="An error occurred while trying to ban the user. Make sure my role is above the role of the user you want to ban.",
|
||
|
|
color=0xE02B2B,
|
||
|
|
)
|
||
|
|
await context.send(embed=embed)
|
||
|
|
|
||
|
|
|
||
|
|
async def setup(bot) -> None:
|
||
|
|
await bot.add_cog(Ban(bot))
|