33Description:
44This is a template to create your own discord bot in python.
55
6- Version: 5.0
6+ Version: 5.1
77"""
88
9- from doctest import debug_script
109import discord
1110from discord import app_commands
1211from discord .ext import commands
@@ -152,14 +151,23 @@ async def ban(self, context: Context, user: discord.User, reason: str = "Not spe
152151 )
153152 await context .send (embed = embed )
154153
155- @commands .hybrid_command (
156- name = "warn " ,
157- description = "Warns a user in the server." ,
154+ @commands .hybrid_group (
155+ name = "warning " ,
156+ description = "Manage warnings of a user on a server." ,
158157 )
159158 @commands .has_permissions (manage_messages = True )
160159 @checks .not_blacklisted ()
160+ async def warning (self , context : Context ) -> None :
161+ pass
162+
163+ @warning .command (
164+ name = "add" ,
165+ description = "Adds a warning to a user in the server." ,
166+ )
167+ @checks .not_blacklisted ()
168+ @commands .has_permissions (manage_messages = True )
161169 @app_commands .describe (user = "The user that should be warned." , reason = "The reason why the user should be warned." )
162- async def warn (self , context : Context , user : discord .User , reason : str = "Not specified" ) -> None :
170+ async def warning_add (self , context : Context , user : discord .User , reason : str = "Not specified" ) -> None :
163171 """
164172 Warns a user in his private messages.
165173
@@ -185,14 +193,38 @@ async def warn(self, context: Context, user: discord.User, reason: str = "Not sp
185193 # Couldn't send a message in the private messages of the user
186194 await context .send (f"{ member .mention } , you were warned by **{ context .author } **!\n Reason: { reason } " )
187195
188- @commands .hybrid_command (
189- name = "warnings" ,
196+ @warning .command (
197+ name = "remove" ,
198+ description = "Removes a warning from a user in the server." ,
199+ )
200+ @checks .not_blacklisted ()
201+ @commands .has_permissions (manage_messages = True )
202+ @app_commands .describe (user = "The user that should get their warning removed." , warn_id = "The ID of the warning that should be removed." )
203+ async def warning_add (self , context : Context , user : discord .User , warn_id : int ) -> None :
204+ """
205+ Warns a user in his private messages.
206+
207+ :param context: The hybrid command context.
208+ :param user: The user that should get their warning removed.
209+ :param warn_id: The ID of the warning that should be removed.
210+ """
211+ member = context .guild .get_member (user .id ) or await context .guild .fetch_member (user .id )
212+ total = db_manager .remove_warn (warn_id , user .id , context .guild .id )
213+ embed = discord .Embed (
214+ title = "User Warn Removed!" ,
215+ description = f"I've removed the warning **#{ warn_id } ** from **{ member } **!\n Total warns for this user: { total } " ,
216+ color = 0x9C84EF
217+ )
218+ await context .send (embed = embed )
219+
220+ @warning .command (
221+ name = "list" ,
190222 description = "Shows the warnings of a user in the server." ,
191223 )
192224 @commands .has_guild_permissions (manage_messages = True )
193225 @checks .not_blacklisted ()
194226 @app_commands .describe (user = "The user you want to get the warnings of." )
195- async def warnings (self , context : Context , user : discord .User ):
227+ async def warning_list (self , context : Context , user : discord .User ):
196228 """
197229 Shows the warnings of a user in the server.
198230
@@ -209,7 +241,7 @@ async def warnings(self, context: Context, user: discord.User):
209241 description = "This user has no warnings."
210242 else :
211243 for warning in warnings_list :
212- description += f"• Warned by <@{ warning [2 ]} >: **{ warning [3 ]} ** (<t:{ warning [4 ]} >)\n "
244+ description += f"• Warned by <@{ warning [2 ]} >: **{ warning [3 ]} ** (<t:{ warning [4 ]} >) - Warn ID # { warning [ 5 ] } \n "
213245 embed .description = description
214246 await context .send (embed = embed )
215247
0 commit comments