3
3
Description:
4
4
This is a template to create your own discord bot in python.
5
5
6
- Version: 5.0
6
+ Version: 5.1
7
7
"""
8
8
9
- from doctest import debug_script
10
9
import discord
11
10
from discord import app_commands
12
11
from discord .ext import commands
@@ -152,14 +151,23 @@ async def ban(self, context: Context, user: discord.User, reason: str = "Not spe
152
151
)
153
152
await context .send (embed = embed )
154
153
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." ,
158
157
)
159
158
@commands .has_permissions (manage_messages = True )
160
159
@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 )
161
169
@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 :
163
171
"""
164
172
Warns a user in his private messages.
165
173
@@ -185,14 +193,38 @@ async def warn(self, context: Context, user: discord.User, reason: str = "Not sp
185
193
# Couldn't send a message in the private messages of the user
186
194
await context .send (f"{ member .mention } , you were warned by **{ context .author } **!\n Reason: { reason } " )
187
195
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" ,
190
222
description = "Shows the warnings of a user in the server." ,
191
223
)
192
224
@commands .has_guild_permissions (manage_messages = True )
193
225
@checks .not_blacklisted ()
194
226
@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 ):
196
228
"""
197
229
Shows the warnings of a user in the server.
198
230
@@ -209,7 +241,7 @@ async def warnings(self, context: Context, user: discord.User):
209
241
description = "This user has no warnings."
210
242
else :
211
243
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 "
213
245
embed .description = description
214
246
await context .send (embed = embed )
215
247
0 commit comments