mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 10:51:05 -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
|
from redbot.core.bot import Red
|
||||||
import logging
|
import logging
|
||||||
import discord
|
import discord
|
||||||
|
from discord.app_commands.errors import CommandAlreadyRegistered
|
||||||
from .birthday import Birthday, birthday_context_menu
|
from .birthday import Birthday, birthday_context_menu
|
||||||
|
|
||||||
logger = logging.getLogger("Birthday")
|
logger = logging.getLogger("Birthday")
|
||||||
@@ -11,9 +12,11 @@ async def setup(bot: Red) -> None:
|
|||||||
try:
|
try:
|
||||||
cog = Birthday(bot)
|
cog = Birthday(bot)
|
||||||
await bot.add_cog(cog)
|
await bot.add_cog(cog)
|
||||||
# Add context menu command if it doesn't exist
|
# Try to add context menu command, ignore if already registered
|
||||||
if not discord.utils.get(bot.tree.get_commands(), name="Give Birthday Role"):
|
try:
|
||||||
bot.tree.add_command(birthday_context_menu)
|
bot.tree.add_command(birthday_context_menu)
|
||||||
|
except CommandAlreadyRegistered:
|
||||||
|
pass
|
||||||
# Initialize scheduled tasks
|
# Initialize scheduled tasks
|
||||||
try:
|
try:
|
||||||
await cog.reload_scheduled_tasks()
|
await cog.reload_scheduled_tasks()
|
||||||
|
|||||||
Reference in New Issue
Block a user