Files
Pac-cogs/birthday/__init__.py
pacnpal 172fe83288 Added a command existence check using discord.utils.get()
Only register the command if it's not already present
Maintained all other functionality including cog loading and task initialization
2024-11-15 14:30:50 +00:00

38 lines
1.3 KiB
Python

"""Birthday cog for Red-DiscordBot"""
from redbot.core.bot import Red
import logging
import discord
from .birthday import Birthday, birthday_context_menu
logger = logging.getLogger("Birthday")
async def setup(bot: Red) -> None:
"""Load Birthday cog."""
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"):
bot.tree.add_command(birthday_context_menu)
# Initialize scheduled tasks
try:
await cog.reload_scheduled_tasks()
except Exception as e:
logger.error(f"Failed to initialize scheduled tasks: {str(e)}")
await bot.remove_cog(cog.__class__.__name__)
raise
except Exception as e:
logger.error(f"Failed to load Birthday cog: {str(e)}")
raise
async def teardown(bot: Red) -> None:
"""Clean up when unloading."""
try:
if "Birthday" in bot.cogs:
await bot.remove_cog("Birthday")
# Remove context menu command
bot.tree.remove_command("Give Birthday Role", type=discord.AppCommandType.user)
except Exception as e:
logger.error(f"Error during teardown: {str(e)}")
raise