Update invite links to use dynamic Discord client ID and import necessary configuration constants. Refactor slash command synchronization logic for improved error handling and performance.
Some checks failed
CI / Bot (Python) (push) Failing after 12s
CI / Dashboard (Next.js) (push) Failing after 10s

This commit is contained in:
TheOnlyMace
2026-07-21 22:44:40 +02:00
parent fc77f0a3c2
commit 6b0091f7d5
3 changed files with 14 additions and 14 deletions

View File

@@ -86,7 +86,7 @@ class AvatarView(View):
await interaction.response.edit_message(embed=embed) await interaction.response.edit_message(embed=embed)
from utils.config import BotName from utils.config import BotName, DISCORD_CLIENT_ID
class General(commands.Cog): class General(commands.Cog):
@@ -309,7 +309,7 @@ class General(commands.Cog):
invite_text = ( invite_text = (
"```Empower your server with blazing-fast features and 24/7 support!```\n" "```Empower your server with blazing-fast features and 24/7 support!```\n"
f"{AXIOM_LINKS} **Quick Actions**\n" f"{AXIOM_LINKS} **Quick Actions**\n"
f">>> **[Invite {BotName}](https://discord.com/oauth2/authorize?client_id=1396114795102470196&permissions=8&integration_type=0&scope=bot+applications.commands)**\n" f">>> **[Invite {BotName}](https://discord.com/oauth2/authorize?client_id={DISCORD_CLIENT_ID or (ctx.bot.user.id if ctx.bot.user else '')}&permissions=8&integration_type=0&scope=bot%20applications.commands)**\n"
"**[Support Server](https://discord.gg/hexahost)**" "**[Support Server](https://discord.gg/hexahost)**"
) )
await ctx.send(view=CV2(f"{AXIOM_CONNECTION} {BotName} Integration Hub!", invite_text)) await ctx.send(view=CV2(f"{AXIOM_CONNECTION} {BotName} Integration Hub!", invite_text))

View File

@@ -13,7 +13,7 @@
from utils.db_paths import db_path from utils.db_paths import db_path
from utils import getConfig from utils import getConfig
from utils.config import BotName from utils.config import BotName, DISCORD_CLIENT_ID
import discord import discord
from utils.emoji import ARROWRED, CODEBASE, HEART3, INDEX, AXIOM_LINKS from utils.emoji import ARROWRED, CODEBASE, HEART3, INDEX, AXIOM_LINKS
from discord.ui import LayoutView, TextDisplay, Separator, Container, ActionRow, Select from discord.ui import LayoutView, TextDisplay, Separator, Container, ActionRow, Select
@@ -87,7 +87,7 @@ class MentionSelectView(LayoutView):
) )
elif selected == "Links": elif selected == "Links":
content = ( content = (
f"**[Invite {BotName}](https://discord.com/oauth2/authorize?client_id=1396114795102470196)**\n" f"**[Invite {BotName}](https://discord.com/oauth2/authorize?client_id={DISCORD_CLIENT_ID or (self.bot.user.id if self.bot.user else '')}&permissions=8&scope=bot%20applications.commands)**\n"
"**[Join Support Server](https://discord.gg/hexahost)**" "**[Join Support Server](https://discord.gg/hexahost)**"
) )

View File

@@ -119,31 +119,29 @@ async def sync_slash_commands(
"pruned": removed, "pruned": removed,
} }
async def _try_sync(label: str, coro): async def _try_sync(label: str, factory):
try: try:
synced = await coro synced = await factory()
return synced, None return synced, None
except Exception as e: except Exception as e:
# Drop invalid commands once and retry (common after bulk hybrid conversion)
detail = str(e) detail = str(e)
logger.error("%s failed: %s", label, detail) logger.error("%s failed: %s", label, detail)
dropped = [] dropped = []
for cmd in list(bot.tree.get_commands()): for cmd in list(bot.tree.get_commands()):
# Heuristic: remove cmds whose name appears in the error payload
if cmd.name in detail or getattr(cmd, "qualified_name", "") in detail: if cmd.name in detail or getattr(cmd, "qualified_name", "") in detail:
bot.tree.remove_command(cmd.name) bot.tree.remove_command(cmd.name)
dropped.append(cmd.name) dropped.append(cmd.name)
if dropped: if dropped:
print(f"\033[33m◈ Removed invalid slash cmd(s) after error: {', '.join(dropped)}\033[0m") print(f"\033[33m◈ Removed invalid slash cmd(s) after error: {', '.join(dropped)}\033[0m")
try: try:
synced = await coro synced = await factory()
return synced, None return synced, None
except Exception as e2: except Exception as e2:
return None, f"{label}: {e2}" return None, f"{label}: {e2}"
return None, f"{label}: {e}" return None, f"{label}: {e}"
if do_global: if do_global:
synced, err = await _try_sync("Global slash sync", bot.tree.sync()) synced, err = await _try_sync("Global slash sync", lambda: bot.tree.sync())
if err: if err:
result["errors"].append(err) result["errors"].append(err)
print(f"\033[31m◈ {err}\033[0m") print(f"\033[31m◈ {err}\033[0m")
@@ -162,11 +160,13 @@ async def sync_slash_commands(
for guild in target_guilds: for guild in target_guilds:
gid = getattr(guild, "id", guild) gid = getattr(guild, "id", guild)
async def _guild_sync(g=guild): def _make_factory(g=guild):
async def _factory():
bot.tree.copy_global_to(guild=g) bot.tree.copy_global_to(guild=g)
return await bot.tree.sync(guild=g) return await bot.tree.sync(guild=g)
return _factory
synced, err = await _try_sync(f"Guild {gid} slash sync", _guild_sync()) synced, err = await _try_sync(f"Guild {gid} slash sync", _make_factory())
if err: if err:
result["errors"].append(err) result["errors"].append(err)
print(f"\033[31m◈ {err}\033[0m") print(f"\033[31m◈ {err}\033[0m")