diff --git a/birthday/__init__.py b/birthday/__init__.py index 9587a2d..604e2a7 100644 --- a/birthday/__init__.py +++ b/birthday/__init__.py @@ -1,7 +1,30 @@ +"""Birthday cog for Red-DiscordBot""" +from redbot.core.bot import Red from .birthday import Birthday -__red_end_user_data_statement__ = "This allows users with the set roles to give the birthday role to users until the end of the day." +async def setup(bot: Red) -> None: + """Load Birthday cog.""" + cog = Birthday(bot) + # Add cog first + await bot.add_cog(cog) + # Then sync commands after cog is loaded + if hasattr(bot, "tree"): + try: + # Only sync guild commands to avoid rate limits + await bot.tree.sync(guild=None) + except Exception as e: + # Log error but don't fail cog load + bot.log.error(f"Failed to sync commands: {str(e)}") - -async def setup(bot): - await bot.add_cog(Birthday(bot)) \ No newline at end of file +async def teardown(bot: Red) -> None: + """Clean up when unloading.""" + if hasattr(bot, "tree"): + try: + # Remove all commands from this cog + for command in bot.tree.get_commands(): + bot.tree.remove_command(command.name) + # Sync to remove commands from Discord + await bot.tree.sync(guild=None) + except Exception as e: + # Log error but don't fail cog unload + bot.log.error(f"Failed to cleanup commands: {str(e)}") diff --git a/overseerr/__init__.py b/overseerr/__init__.py index 38736ea..3cf17e8 100644 --- a/overseerr/__init__.py +++ b/overseerr/__init__.py @@ -1,7 +1,30 @@ +"""Overseerr cog for Red-DiscordBot""" +from redbot.core.bot import Red from .overseerr import Overseerr -__red_end_user_data_statement__ = "This allows users to make requests to Overseerr and Admins can approve them." +async def setup(bot: Red) -> None: + """Load Overseerr cog.""" + cog = Overseerr(bot) + # Add cog first + await bot.add_cog(cog) + # Then sync commands after cog is loaded + if hasattr(bot, "tree"): + try: + # Only sync guild commands to avoid rate limits + await bot.tree.sync(guild=None) + except Exception as e: + # Log error but don't fail cog load + bot.log.error(f"Failed to sync commands: {str(e)}") - -async def setup(bot): - await bot.add_cog(Overseerr(bot)) \ No newline at end of file +async def teardown(bot: Red) -> None: + """Clean up when unloading.""" + if hasattr(bot, "tree"): + try: + # Remove all commands from this cog + for command in bot.tree.get_commands(): + bot.tree.remove_command(command.name) + # Sync to remove commands from Discord + await bot.tree.sync(guild=None) + except Exception as e: + # Log error but don't fail cog unload + bot.log.error(f"Failed to cleanup commands: {str(e)}")