33Description:
44This is a template to create your own discord bot in python.
55
6- Version: 4.1
6+ Version: 4.1.1
77"""
88
99import json
@@ -150,32 +150,59 @@ async def on_slash_command(interaction: ApplicationCommandInteraction) -> None:
150150async def on_slash_command_error (interaction : ApplicationCommandInteraction , error : Exception ) -> None :
151151 """
152152 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+
153156 :param interaction: The slash command that failed executing.
154157 :param error: The error that has been faced.
155158 """
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 ):
157170 """
158171 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.
162173 """
163174 embed = disnake .Embed (
164175 title = "Error!" ,
165176 description = "You are blacklisted from using the bot." ,
166177 color = 0xE02B2B
167178 )
168- print ("A blacklisted user tried to execute a command." )
169179 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 ):
171191 embed = disnake .Embed (
172192 title = "Error!" ,
173193 description = "You are missing the permission(s) `" + ", " .join (
174194 error .missing_permissions ) + "` to execute this command!" ,
175195 color = 0xE02B2B
176196 )
177- print ("A blacklisted user tried to execute a command." )
178197 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 )
179206 raise error
180207
181208
@@ -196,7 +223,7 @@ async def on_command_completion(context: Context) -> None:
196223async def on_command_error (context : Context , error ) -> None :
197224 """
198225 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.
200227 :param error: The error that has been faced.
201228 """
202229 if isinstance (error , commands .CommandOnCooldown ):
@@ -209,6 +236,27 @@ async def on_command_error(context: Context, error) -> None:
209236 color = 0xE02B2B
210237 )
211238 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 )
212260 elif isinstance (error , commands .MissingPermissions ):
213261 embed = disnake .Embed (
214262 title = "Error!" ,
0 commit comments