3
3
Description:
4
4
This is a template to create your own discord bot in python.
5
5
6
- Version: 4.1
6
+ Version: 4.1.1
7
7
"""
8
8
9
9
import json
@@ -150,32 +150,59 @@ async def on_slash_command(interaction: ApplicationCommandInteraction) -> None:
150
150
async def on_slash_command_error (interaction : ApplicationCommandInteraction , error : Exception ) -> None :
151
151
"""
152
152
The code in this event is executed every time a valid slash command catches an error
153
+
154
+ 'ephemeral=True' will make so that only the user who execute the command can see the message
155
+
153
156
:param interaction: The slash command that failed executing.
154
157
:param error: The error that has been faced.
155
158
"""
156
- if isinstance (error , exceptions .UserBlacklisted ):
159
+ if isinstance (error , commands .CommandOnCooldown ):
160
+ minutes , seconds = divmod (error .retry_after , 60 )
161
+ hours , minutes = divmod (minutes , 60 )
162
+ hours = hours % 24
163
+ embed = disnake .Embed (
164
+ title = "Hey, please slow down!" ,
165
+ description = f"You can use this command again in { f'{ round (hours )} hours' if round (hours ) > 0 else '' } { f'{ round (minutes )} minutes' if round (minutes ) > 0 else '' } { f'{ round (seconds )} seconds' if round (seconds ) > 0 else '' } ." ,
166
+ color = 0xE02B2B
167
+ )
168
+ return await interaction .send (embed = embed , ephemeral = True )
169
+ elif isinstance (error , exceptions .UserBlacklisted ):
157
170
"""
158
171
The code here will only execute if the error is an instance of 'UserBlacklisted', which can occur when using
159
- the @checks.is_owner() check in your command, or you can raise the error by yourself.
160
-
161
- 'hidden=True' will make so that only the user who execute the command can see the message
172
+ the @checks.not_blacklisted() check in your command, or you can raise the error by yourself.
162
173
"""
163
174
embed = disnake .Embed (
164
175
title = "Error!" ,
165
176
description = "You are blacklisted from using the bot." ,
166
177
color = 0xE02B2B
167
178
)
168
- print ("A blacklisted user tried to execute a command." )
169
179
return await interaction .send (embed = embed , ephemeral = True )
170
- elif isinstance (error , commands .errors .MissingPermissions ):
180
+ elif isinstance (error , exceptions .UserNotOwner ):
181
+ """
182
+ Same as above, just for the @checks.is_owner() check.
183
+ """
184
+ embed = disnake .Embed (
185
+ title = "Error!" ,
186
+ description = "You are not the owner of the bot!" ,
187
+ color = 0xE02B2B
188
+ )
189
+ return await interaction .send (embed = embed , ephemeral = True )
190
+ elif isinstance (error , commands .MissingPermissions ):
171
191
embed = disnake .Embed (
172
192
title = "Error!" ,
173
193
description = "You are missing the permission(s) `" + ", " .join (
174
194
error .missing_permissions ) + "` to execute this command!" ,
175
195
color = 0xE02B2B
176
196
)
177
- print ("A blacklisted user tried to execute a command." )
178
197
return await interaction .send (embed = embed , ephemeral = True )
198
+ elif isinstance (error , commands .MissingRequiredArgument ):
199
+ embed = disnake .Embed (
200
+ title = "Error!" ,
201
+ # We need to capitalize because the command arguments have no capital letter in the code.
202
+ description = str (error ).capitalize (),
203
+ color = 0xE02B2B
204
+ )
205
+ await interaction .send (embed = embed , ephemeral = True )
179
206
raise error
180
207
181
208
@@ -196,7 +223,7 @@ async def on_command_completion(context: Context) -> None:
196
223
async def on_command_error (context : Context , error ) -> None :
197
224
"""
198
225
The code in this event is executed every time a normal valid command catches an error
199
- :param context: The normal command that failed executing.
226
+ :param context: The context of the normal command that failed executing.
200
227
:param error: The error that has been faced.
201
228
"""
202
229
if isinstance (error , commands .CommandOnCooldown ):
@@ -209,6 +236,27 @@ async def on_command_error(context: Context, error) -> None:
209
236
color = 0xE02B2B
210
237
)
211
238
await context .send (embed = embed )
239
+ elif isinstance (error , exceptions .UserBlacklisted ):
240
+ """
241
+ The code here will only execute if the error is an instance of 'UserBlacklisted', which can occur when using
242
+ the @checks.not_blacklisted() check in your command, or you can raise the error by yourself.
243
+ """
244
+ embed = disnake .Embed (
245
+ title = "Error!" ,
246
+ description = "You are blacklisted from using the bot." ,
247
+ color = 0xE02B2B
248
+ )
249
+ await context .send (embed = embed )
250
+ elif isinstance (error , exceptions .UserNotOwner ):
251
+ """
252
+ Same as above, just for the @checks.is_owner() check.
253
+ """
254
+ embed = disnake .Embed (
255
+ title = "Error!" ,
256
+ description = "You are not the owner of the bot!" ,
257
+ color = 0xE02B2B
258
+ )
259
+ await context .send (embed = embed )
212
260
elif isinstance (error , commands .MissingPermissions ):
213
261
embed = disnake .Embed (
214
262
title = "Error!" ,
0 commit comments