mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
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
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user