2025-09-14 18:54:56 -04:00
import discord
from discord import app_commands
from discord . ext import commands
from discord . ext . commands import Context
2025-09-28 23:07:46 -04:00
def warnings_command ( ) :
async def send_embed ( context , embed : discord . Embed , * , ephemeral : bool = False ) - > None :
2025-09-16 06:57:12 -04:00
interaction = getattr ( context , " interaction " , None )
if interaction is not None :
if interaction . response . is_done ( ) :
await interaction . followup . send ( embed = embed , ephemeral = ephemeral )
else :
await interaction . response . send_message ( embed = embed , ephemeral = ephemeral )
else :
await context . send ( embed = embed )
2025-09-14 18:54:56 -04:00
@commands.hybrid_group (
name = " warning " ,
description = " Manage warnings of a user on a server. " ,
)
2025-09-28 23:07:46 -04:00
async def warning ( self , context ) - > None :
2025-09-14 18:54:56 -04:00
"""
Manage warnings of a user on a server .
: param context : The hybrid command context .
"""
2025-09-16 06:57:12 -04:00
if not context . author . guild_permissions . manage_messages :
embed = discord . Embed (
title = " Missing Permissions! " ,
description = " You are missing the permission(s) `manage_messages` to execute this command! " ,
color = 0xE02B2B ,
2025-09-28 13:19:28 -04:00
) . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-16 06:57:12 -04:00
return await self . send_embed ( context , embed , ephemeral = True )
2025-09-14 18:54:56 -04:00
if context . invoked_subcommand is None :
embed = discord . Embed (
2025-09-16 07:17:33 -04:00
title = " Warning " ,
2025-09-14 18:54:56 -04:00
description = " Please specify a subcommand. \n \n **Subcommands:** \n `add` - Add a warning to a user. \n `remove` - Remove a warning from a user. \n `list` - List all warnings of a user. " ,
2025-09-16 06:57:12 -04:00
color = 0x7289DA ,
2025-09-14 18:54:56 -04:00
)
2025-09-28 13:19:28 -04:00
embed . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-16 06:57:12 -04:00
await self . send_embed ( context , embed )
2025-09-14 18:54:56 -04:00
@warning.command (
name = " add " ,
description = " Adds a warning to a user in the server. " ,
)
@app_commands.describe (
user = " The user that should be warned. " ,
reason = " The reason why the user should be warned. " ,
)
async def warning_add (
self , context : Context , user : discord . User , * , reason : str = " Not specified "
) - > None :
"""
Warns a user in his private messages .
: param context : The hybrid command context .
: param user : The user that should be warned .
: param reason : The reason for the warn . Default is " Not specified " .
"""
2025-09-16 06:57:12 -04:00
if not context . author . guild_permissions . manage_messages :
embed = discord . Embed (
title = " Missing Permissions! " ,
description = " You are missing the permission(s) `manage_messages` to execute this command! " ,
color = 0xE02B2B ,
2025-09-28 13:19:28 -04:00
) . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-16 06:57:12 -04:00
return await self . send_embed ( context , embed , ephemeral = True )
2025-09-14 18:54:56 -04:00
member = context . guild . get_member ( user . id ) or await context . guild . fetch_member (
user . id
)
total = await self . bot . database . add_warn (
user . id , context . guild . id , context . author . id , reason
)
embed = discord . Embed (
2025-09-16 06:57:12 -04:00
title = " Warning " ,
2025-09-14 18:54:56 -04:00
description = f " ** { member } ** was warned by ** { context . author } **! \n Total warns for this user: { total } " ,
2025-09-16 06:57:12 -04:00
color = 0x7289DA ,
2025-09-14 18:54:56 -04:00
)
2025-09-28 13:19:28 -04:00
embed . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-14 18:54:56 -04:00
embed . add_field ( name = " Reason: " , value = reason )
2025-09-16 06:57:12 -04:00
await self . send_embed ( context , embed )
2025-09-14 18:54:56 -04:00
try :
2025-09-16 06:57:12 -04:00
dm_embed = discord . Embed (
title = " Warning " ,
description = f " You were warned by ** { context . author } ** in ** { context . guild . name } **! \n Reason: { reason } " ,
color = 0xE02B2B ,
2025-09-14 18:54:56 -04:00
)
2025-09-28 13:19:28 -04:00
dm_embed . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-16 06:57:12 -04:00
await member . send ( embed = dm_embed )
2025-09-14 18:54:56 -04:00
except :
2025-09-16 06:57:12 -04:00
fallback = discord . Embed (
2025-09-16 07:17:33 -04:00
title = " Warning " ,
2025-09-16 06:57:12 -04:00
description = f " { member . mention } , you were warned by ** { context . author } **! \n Reason: { reason } " ,
color = 0xE02B2B ,
2025-09-14 18:54:56 -04:00
)
2025-09-16 06:57:12 -04:00
await self . send_embed ( context , fallback )
2025-09-14 18:54:56 -04:00
@warning.command (
name = " remove " ,
description = " Removes a warning from a user in the server. " ,
)
@app_commands.describe (
user = " The user that should get their warning removed. " ,
warn_id = " The ID of the warning that should be removed. " ,
)
async def warning_remove (
self , context : Context , user : discord . User , warn_id : int
) - > None :
"""
Removes a warning from a user .
: param context : The hybrid command context .
: param user : The user that should get their warning removed .
: param warn_id : The ID of the warning that should be removed .
"""
2025-09-16 06:57:12 -04:00
if not context . author . guild_permissions . manage_messages :
embed = discord . Embed (
title = " Missing Permissions! " ,
description = " You are missing the permission(s) `manage_messages` to execute this command! " ,
color = 0xE02B2B ,
2025-09-28 13:19:28 -04:00
) . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-16 06:57:12 -04:00
return await self . send_embed ( context , embed , ephemeral = True )
2025-09-14 18:54:56 -04:00
member = context . guild . get_member ( user . id ) or await context . guild . fetch_member (
user . id
)
total = await self . bot . database . remove_warn ( warn_id , user . id , context . guild . id )
embed = discord . Embed (
2025-09-16 07:17:33 -04:00
title = " Warning " ,
2025-09-16 12:33:45 -04:00
description = f " Removed the warning **# { warn_id } ** from ** { member } **! \n Total warns for this user: { total } " ,
2025-09-16 06:57:12 -04:00
color = 0x7289DA ,
2025-09-14 18:54:56 -04:00
)
2025-09-28 13:19:28 -04:00
embed . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-16 06:57:12 -04:00
await self . send_embed ( context , embed )
2025-09-14 18:54:56 -04:00
@warning.command (
name = " list " ,
description = " Shows the warnings of a user in the server. " ,
)
@app_commands.describe ( user = " The user you want to get the warnings of. " )
async def warning_list ( self , context : Context , user : discord . User ) - > None :
"""
Shows the warnings of a user in the server .
: param context : The hybrid command context .
: param user : The user you want to get the warnings of .
"""
2025-09-16 06:57:12 -04:00
if not context . author . guild_permissions . manage_messages :
embed = discord . Embed (
title = " Missing Permissions! " ,
description = " You are missing the permission(s) `manage_messages` to execute this command! " ,
color = 0xE02B2B ,
2025-09-28 13:19:28 -04:00
) . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-16 06:57:12 -04:00
return await self . send_embed ( context , embed , ephemeral = True )
2025-09-14 18:54:56 -04:00
warnings_list = await self . bot . database . get_warnings ( user . id , context . guild . id )
2025-09-16 06:57:12 -04:00
embed = discord . Embed ( title = f " Warnings of { user } " , color = 0x7289DA )
2025-09-28 13:19:28 -04:00
embed . set_author ( name = " Moderation " , icon_url = " https://yes.nighty.works/raw/CPKHQd.png " )
2025-09-14 18:54:56 -04:00
description = " "
if len ( warnings_list ) == 0 :
description = " This user has no warnings. "
else :
for warning in warnings_list :
description + = f " • Warned by <@ { warning [ 2 ] } >: ** { warning [ 3 ] } ** (<t: { warning [ 4 ] } >) - Warn ID # { warning [ 5 ] } \n "
embed . description = description
2025-09-16 06:57:12 -04:00
await self . send_embed ( context , embed )
2025-09-14 18:54:56 -04:00
2025-09-28 23:07:46 -04:00
return warning