From 245710e4d427b7e7141cd262842d917b6d3c2857 Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:32:33 +0000 Subject: [PATCH] Added explicit import of CommandAlreadyRegistered exception Wrapped the command registration in a try-except block Silently continues if the command is already registered Maintains all other functionality including cog loading and task initialization --- birthday/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/birthday/__init__.py b/birthday/__init__.py index 369be29..458d106 100644 --- a/birthday/__init__.py +++ b/birthday/__init__.py @@ -2,6 +2,7 @@ from redbot.core.bot import Red import logging import discord +from discord.app_commands.errors import CommandAlreadyRegistered from .birthday import Birthday, birthday_context_menu logger = logging.getLogger("Birthday") @@ -11,9 +12,11 @@ async def setup(bot: Red) -> None: try: cog = Birthday(bot) await bot.add_cog(cog) - # Add context menu command if it doesn't exist - if not discord.utils.get(bot.tree.get_commands(), name="Give Birthday Role"): + # Try to add context menu command, ignore if already registered + try: bot.tree.add_command(birthday_context_menu) + except CommandAlreadyRegistered: + pass # Initialize scheduled tasks try: await cog.reload_scheduled_tasks()