From 104aab3681b1c125b5d21ea14761b4387e0e9696 Mon Sep 17 00:00:00 2001 From: wlinator Date: Sun, 1 Sep 2024 08:02:55 -0400 Subject: [PATCH] feat: Fix birthday check handling --- handlers/error.py | 4 ++++ lib/checks.py | 14 +++++++------- lib/exceptions.py | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/handlers/error.py b/handlers/error.py index f2bd706..7464256 100644 --- a/handlers/error.py +++ b/handlers/error.py @@ -53,6 +53,10 @@ class ErrorHandler(commands.Cog): self._old_tree_error = tree.on_error tree.on_error = self.on_app_command_error + async def cog_unload(self): + tree = self.bot.tree + tree.on_error = self._old_tree_error + async def on_app_command_error( self, interaction: discord.Interaction, diff --git a/lib/checks.py b/lib/checks.py index 09d58f8..9443b10 100644 --- a/lib/checks.py +++ b/lib/checks.py @@ -1,19 +1,19 @@ -from discord.ext import commands +import discord +from discord import app_commands from lib.exceptions import BirthdaysDisabled from services.config_service import GuildConfig def birthdays_enabled(): - async def predicate(ctx: commands.Context[commands.Bot]) -> bool: - if ctx.guild is None: + async def predicate(interaction: discord.Interaction) -> bool: + if interaction.guild is None: return True - guild_config = GuildConfig(ctx.guild.id) - - if not guild_config.birthday_channel_id: + guild_config = GuildConfig(interaction.guild.id) + if guild_config.birthday_channel_id is None: raise BirthdaysDisabled return True - return commands.check(predicate) + return app_commands.check(predicate) diff --git a/lib/exceptions.py b/lib/exceptions.py index 792b0aa..3a21630 100644 --- a/lib/exceptions.py +++ b/lib/exceptions.py @@ -1,9 +1,10 @@ +from discord import app_commands from discord.ext import commands from lib.const import CONST -class BirthdaysDisabled(commands.CheckFailure): +class BirthdaysDisabled(commands.CheckFailure, app_commands.CheckFailure): """ Raised when the birthdays module is disabled in ctx.guild. """