This commit is contained in:
Franz Rolfsvaag 2025-08-10 20:41:50 +02:00
parent 7222239774
commit c540f624af

View File

@ -897,13 +897,36 @@ class SpicePayCog(commands.Cog):
# ------------------------ setup ------------------------
async def setup(bot):
async def setup(bot: commands.Bot):
cog = SpicePayCog(bot)
await bot.add_cog(cog)
home_gid = cfg(bot).int('home_guild_id', 0)
# If you use cfg(bot), great; otherwise fall back to DEFAULT.
try:
from modules.common.settings import cfg as _cfg
home_gid = _cfg(bot).int('home_guild_id', 0)
except Exception:
try:
home_gid = int(bot.config['DEFAULT'].get('home_guild_id', '0'))
except Exception:
home_gid = 0
guild_obj = discord.Object(id=home_gid) if home_gid else None
# Make reloads safe: remove if present, then add.
def _rm(name: str):
try:
bot.tree.remove_command(name, guild=guild_obj)
except Exception:
try:
bot.tree.remove_command(name, guild=None)
except Exception:
pass
for name in ("spicepay", "spicepay_resume", "spicepay_cancel", "spicepay_config"):
_rm(name)
if home_gid:
guild_obj = discord.Object(id=home_gid)
bot.tree.add_command(cog.spicepay, guild=guild_obj)
bot.tree.add_command(cog.spicepay_resume, guild=guild_obj)
bot.tree.add_command(cog.spicepay_cancel, guild=guild_obj)