Skip to content

Commit

Permalink
Template v4.1.1
Browse files Browse the repository at this point in the history
* Fixed the custom checks not being sent in the channels correctly.
  • Loading branch information
kkrypt0nn committed Jul 18, 2022
1 parent 5f38f82 commit 7d6d8ef
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 24 deletions.
4 changes: 4 additions & 0 deletions UPDATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

### Version 4.1.1 (18 July 2022)

* Fixed the custom checks not being sent in the channels correctly.

### Version 4.1 (09 January 2022)

* Added the `hackban` command
Expand Down
66 changes: 57 additions & 9 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import json
Expand Down Expand Up @@ -150,32 +150,59 @@ async def on_slash_command(interaction: ApplicationCommandInteraction) -> None:
async def on_slash_command_error(interaction: ApplicationCommandInteraction, error: Exception) -> None:
"""
The code in this event is executed every time a valid slash command catches an error
'ephemeral=True' will make so that only the user who execute the command can see the message
:param interaction: The slash command that failed executing.
:param error: The error that has been faced.
"""
if isinstance(error, exceptions.UserBlacklisted):
if isinstance(error, commands.CommandOnCooldown):
minutes, seconds = divmod(error.retry_after, 60)
hours, minutes = divmod(minutes, 60)
hours = hours % 24
embed = disnake.Embed(
title="Hey, please slow down!",
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 ''}.",
color=0xE02B2B
)
return await interaction.send(embed=embed, ephemeral=True)
elif isinstance(error, exceptions.UserBlacklisted):
"""
The code here will only execute if the error is an instance of 'UserBlacklisted', which can occur when using
the @checks.is_owner() check in your command, or you can raise the error by yourself.
'hidden=True' will make so that only the user who execute the command can see the message
the @checks.not_blacklisted() check in your command, or you can raise the error by yourself.
"""
embed = disnake.Embed(
title="Error!",
description="You are blacklisted from using the bot.",
color=0xE02B2B
)
print("A blacklisted user tried to execute a command.")
return await interaction.send(embed=embed, ephemeral=True)
elif isinstance(error, commands.errors.MissingPermissions):
elif isinstance(error, exceptions.UserNotOwner):
"""
Same as above, just for the @checks.is_owner() check.
"""
embed = disnake.Embed(
title="Error!",
description="You are not the owner of the bot!",
color=0xE02B2B
)
return await interaction.send(embed=embed, ephemeral=True)
elif isinstance(error, commands.MissingPermissions):
embed = disnake.Embed(
title="Error!",
description="You are missing the permission(s) `" + ", ".join(
error.missing_permissions) + "` to execute this command!",
color=0xE02B2B
)
print("A blacklisted user tried to execute a command.")
return await interaction.send(embed=embed, ephemeral=True)
elif isinstance(error, commands.MissingRequiredArgument):
embed = disnake.Embed(
title="Error!",
# We need to capitalize because the command arguments have no capital letter in the code.
description=str(error).capitalize(),
color=0xE02B2B
)
await interaction.send(embed=embed, ephemeral=True)
raise error


Expand All @@ -196,7 +223,7 @@ async def on_command_completion(context: Context) -> None:
async def on_command_error(context: Context, error) -> None:
"""
The code in this event is executed every time a normal valid command catches an error
:param context: The normal command that failed executing.
:param context: The context of the normal command that failed executing.
:param error: The error that has been faced.
"""
if isinstance(error, commands.CommandOnCooldown):
Expand All @@ -209,6 +236,27 @@ async def on_command_error(context: Context, error) -> None:
color=0xE02B2B
)
await context.send(embed=embed)
elif isinstance(error, exceptions.UserBlacklisted):
"""
The code here will only execute if the error is an instance of 'UserBlacklisted', which can occur when using
the @checks.not_blacklisted() check in your command, or you can raise the error by yourself.
"""
embed = disnake.Embed(
title="Error!",
description="You are blacklisted from using the bot.",
color=0xE02B2B
)
await context.send(embed=embed)
elif isinstance(error, exceptions.UserNotOwner):
"""
Same as above, just for the @checks.is_owner() check.
"""
embed = disnake.Embed(
title="Error!",
description="You are not the owner of the bot!",
color=0xE02B2B
)
await context.send(embed=embed)
elif isinstance(error, commands.MissingPermissions):
embed = disnake.Embed(
title="Error!",
Expand Down
2 changes: 1 addition & 1 deletion cogs/normal/fun-normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import random
Expand Down
2 changes: 1 addition & 1 deletion cogs/normal/general-normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import platform
Expand Down
2 changes: 1 addition & 1 deletion cogs/normal/moderation-normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import disnake
Expand Down
2 changes: 1 addition & 1 deletion cogs/normal/owner-normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import json
Expand Down
2 changes: 1 addition & 1 deletion cogs/normal/template-normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

from disnake.ext import commands
Expand Down
2 changes: 1 addition & 1 deletion cogs/slash/fun-slash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import random
Expand Down
2 changes: 1 addition & 1 deletion cogs/slash/general-slash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import platform
Expand Down
2 changes: 1 addition & 1 deletion cogs/slash/moderation-slash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import disnake
Expand Down
2 changes: 1 addition & 1 deletion cogs/slash/owner-slash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import json
Expand Down
2 changes: 1 addition & 1 deletion cogs/slash/template-slash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

from disnake import ApplicationCommandInteraction
Expand Down
8 changes: 5 additions & 3 deletions exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

from disnake.ext import commands

class UserBlacklisted(Exception):

class UserBlacklisted(commands.CheckFailure):
"""
Thrown when a user is attempting something, but is blacklisted.
"""
Expand All @@ -17,7 +19,7 @@ def __init__(self, message="User is blacklisted!"):
super().__init__(self.message)


class UserNotOwner(Exception):
class UserNotOwner(commands.CheckFailure):
"""
Thrown when a user is attempting something, but is not an owner of the bot.
"""
Expand Down
2 changes: 1 addition & 1 deletion helpers/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import json
Expand Down
2 changes: 1 addition & 1 deletion helpers/json_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is a template to create your own discord bot in python.
Version: 4.1
Version: 4.1.1
"""

import json
Expand Down

0 comments on commit 7d6d8ef

Please sign in to comment.