mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 03:40:11 +01:00
60 lines
2.0 KiB
Python
60 lines
2.0 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 HackBan(commands.Cog, name="hackban"):
|
|
def __init__(self, bot) -> None:
|
|
self.bot = bot
|
|
|
|
@commands.hybrid_command(
|
|
name="hackban",
|
|
description="Bans a user without the user having to be in the server.",
|
|
)
|
|
@commands.has_permissions(ban_members=True)
|
|
@commands.bot_has_permissions(ban_members=True)
|
|
@app_commands.describe(
|
|
user_id="The user ID that should be banned.",
|
|
reason="The reason why the user should be banned.",
|
|
)
|
|
async def hackban(
|
|
self, context: Context, user_id: str, *, reason: str = "Not specified"
|
|
) -> None:
|
|
"""
|
|
Bans a user without the user having to be in the server.
|
|
|
|
:param context: The hybrid command context.
|
|
:param user_id: The ID of the user that should be banned.
|
|
:param reason: The reason for the ban. Default is "Not specified".
|
|
"""
|
|
try:
|
|
await self.bot.http.ban(user_id, context.guild.id, reason=reason)
|
|
user = self.bot.get_user(int(user_id)) or await self.bot.fetch_user(
|
|
int(user_id)
|
|
)
|
|
embed = discord.Embed(
|
|
description=f"**{user}** (ID: {user_id}) was banned by **{context.author}**!",
|
|
color=0xBEBEFE,
|
|
)
|
|
embed.add_field(name="Reason:", value=reason)
|
|
await context.send(embed=embed)
|
|
except Exception:
|
|
embed = discord.Embed(
|
|
description="An error occurred while trying to ban the user. Make sure ID is an existing ID that belongs to a user.",
|
|
color=0xE02B2B,
|
|
)
|
|
await context.send(embed=embed)
|
|
|
|
|
|
async def setup(bot) -> None:
|
|
await bot.add_cog(HackBan(bot))
|