aboutsummaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-03-31 00:11:35 -0500
committerParker <contact@pkrm.dev>2024-03-31 00:11:35 -0500
commit7a4cadfdce9208aa3ae720d547851dfed190788f (patch)
tree44c6ff54043674c776b1d5ea2a527c5c2b2e7ef4 /code
parentc371c1d34452426956cb1bbac5a53e36a3d9d7d5 (diff)
Error handlers
Diffstat (limited to 'code')
-rw-r--r--code/cogs/slash_handlers.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/code/cogs/slash_handlers.py b/code/cogs/slash_handlers.py
new file mode 100644
index 0000000..884fc4c
--- /dev/null
+++ b/code/cogs/slash_handlers.py
@@ -0,0 +1,91 @@
+import discord
+from discord.ext import commands
+from discord import app_commands
+from discord.ext.commands.errors import *
+import datetime
+
+from global_variables import BOT_COLOR
+
+
+class slash_handlers(commands.Cog):
+ def __init__(self, bot):
+ self.bot = bot
+ bot.tree.on_error = self.on_error
+
+ async def on_error(self, interaction: discord.Interaction, error):
+ music_commands = [
+ "play",
+ "clear",
+ "np",
+ "pause",
+ "queue",
+ "remove",
+ "resume",
+ "shuffle",
+ "skip",
+ "stop",
+ ]
+
+ if isinstance(error, CommandNotFound):
+ return
+
+ # elif isinstance(error, app_commands.MissingPermissions):
+ # embed = discord.Embed(
+ # title="Missing Permissions!",
+ # description=f"{error}",
+ # color=BOT_COLOR
+ # )
+ # await interaction.response.send_message(embed=embed, ephemeral=True)
+
+ # elif isinstance(error, app_commands.BotMissingPermissions):
+ # embed = discord.Embed(
+ # title="Bot Missing Permissions!",
+ # description=f"{error}",
+ # color=BOT_COLOR
+ # )
+ # await interaction.response.send_message(embed=embed, ephemeral=True)
+
+ elif (
+ isinstance(error, app_commands.AppCommandError)
+ and interaction.command.name in music_commands
+ ):
+ embed = discord.Embed(
+ title=error.args[0]["title"],
+ description=error.args[0]["description"],
+ color=BOT_COLOR,
+ )
+ embed.set_footer(
+ text=datetime.datetime.now(datetime.timezone.utc).strftime(
+ "%Y-%m-%d %H:%M:%S"
+ )
+ + " UTC"
+ )
+ await interaction.response.send_message(embed=embed, ephemeral=True)
+
+ elif (
+ isinstance(error, app_commands.CheckFailure)
+ and interaction.command.name in music_commands
+ ):
+ embed = discord.Embed(
+ title="Player Creation Error",
+ description="An error occured when creating a player. Please try again.",
+ color=BOT_COLOR,
+ )
+ embed.set_footer(
+ text=datetime.datetime.now(datetime.timezone.utc).strftime(
+ "%Y-%m-%d %H:%M:%S"
+ )
+ + " UTC"
+ )
+ await interaction.response.send_message(embed=embed, ephemeral=True)
+
+ else:
+ raise error
+
+ @commands.Cog.listener()
+ async def on_command_error(self, ctx, error):
+ return
+
+
+async def setup(bot: commands.Bot):
+ await bot.add_cog(slash_handlers(bot))