diff --git a/src/bot/root_pythia_bot.py b/src/bot/root_pythia_bot.py index d53a7c8..84104e7 100644 --- a/src/bot/root_pythia_bot.py +++ b/src/bot/root_pythia_bot.py @@ -13,7 +13,7 @@ from bot.dummy_db_manager import DummyDBManager -CHANNEL_ID = getenv("CHANNEL_ID") +CHANNEL_ID = int(getenv("CHANNEL_ID")) def craft_intents(): @@ -50,6 +50,9 @@ def craft_intents(): ########### Setup bot events response ############### +@BOT.check +def is_my_channel(ctx): + return ctx.channel.id == CHANNEL_ID @BOT.event diff --git a/src/bot/root_pythia_cogs.py b/src/bot/root_pythia_cogs.py index 922c310..e0ab293 100644 --- a/src/bot/root_pythia_cogs.py +++ b/src/bot/root_pythia_cogs.py @@ -4,6 +4,7 @@ import discord from discord.ext import commands, tasks +from discord.ext.commands.errors import CheckFailure from pngmaker import NewValidatedChallenge @@ -146,6 +147,16 @@ async def verbose_if_idle(self, channel): @commands.Cog.listener() async def on_command_error(self, ctx, error): + if isinstance(error, CheckFailure): + self.logger.warning( + "discord.ext.commands.errors.CheckFailure (is_my_channel?)" + " was captured by on_command_error: some global check failed" + " for command: '%s' in channel ID '%s'", + ctx.command, + ctx.channel.id, + ) + return + await ctx.send("Command failed, please check logs for more details") await self.verbose_if_idle(ctx)