Skip to content

Commit 7d6d8ef

Browse files
committed
Template v4.1.1
* Fixed the custom checks not being sent in the channels correctly.
1 parent 5f38f82 commit 7d6d8ef

15 files changed

+78
-24
lines changed

UPDATES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Here is the list of all the updates that I made on this template.
44

5+
### Version 4.1.1 (18 July 2022)
6+
7+
* Fixed the custom checks not being sent in the channels correctly.
8+
59
### Version 4.1 (09 January 2022)
610

711
* Added the `hackban` command

bot.py

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import json
@@ -150,32 +150,59 @@ async def on_slash_command(interaction: ApplicationCommandInteraction) -> None:
150150
async 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:
196223
async 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!",

cogs/normal/fun-normal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import random

cogs/normal/general-normal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import platform

cogs/normal/moderation-normal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import disnake

cogs/normal/owner-normal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import json

cogs/normal/template-normal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
from disnake.ext import commands

cogs/slash/fun-slash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import random

cogs/slash/general-slash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import platform

cogs/slash/moderation-slash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import disnake

cogs/slash/owner-slash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import json

cogs/slash/template-slash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
from disnake import ApplicationCommandInteraction

exceptions/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

9+
from disnake.ext import commands
910

10-
class UserBlacklisted(Exception):
11+
12+
class UserBlacklisted(commands.CheckFailure):
1113
"""
1214
Thrown when a user is attempting something, but is blacklisted.
1315
"""
@@ -17,7 +19,7 @@ def __init__(self, message="User is blacklisted!"):
1719
super().__init__(self.message)
1820

1921

20-
class UserNotOwner(Exception):
22+
class UserNotOwner(commands.CheckFailure):
2123
"""
2224
Thrown when a user is attempting something, but is not an owner of the bot.
2325
"""

helpers/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import json

helpers/json_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 4.1
6+
Version: 4.1.1
77
"""
88

99
import json

0 commit comments

Comments
 (0)