Implement slash command synchronization features in environment files and update command definitions to hybrid commands across various cogs. Enhance command registration for improved user experience and streamline command handling in the bot.
This commit is contained in:
32
bot/Axiom.py
32
bot/Axiom.py
@@ -33,6 +33,7 @@ from utils.Tools import *
|
||||
from utils.config import *
|
||||
from utils.emoji import SUCCESS, ERROR, TICK, CROSS, REACTION_TEST_EMOJIS
|
||||
from utils.sync_emojis import run_sync
|
||||
from utils.slash_sync import sync_slash_commands
|
||||
|
||||
import cogs
|
||||
|
||||
@@ -99,21 +100,28 @@ async def on_ready():
|
||||
# Sync application emojis on startup
|
||||
await run_sync(TOKEN)
|
||||
|
||||
async def sync_commands():
|
||||
# Register / slash commands (guild sync = instant; global can take up to ~1h)
|
||||
if not getattr(client, "_slash_synced", False):
|
||||
client._slash_synced = True
|
||||
try:
|
||||
synced = await client.tree.sync()
|
||||
all_commands = list(client.commands)
|
||||
print(f"Synced Total {len(all_commands)} Client Commands and {len(synced)} Slash Commands")
|
||||
await sync_slash_commands(client)
|
||||
except Exception as e:
|
||||
print(f"Error syncing command tree: {e}")
|
||||
print(f"\033[31mError syncing command tree: {e}\033[0m")
|
||||
|
||||
client.loop.create_task(sync_commands())
|
||||
if SERVER_COUNT_CHANNEL_ID or USER_COUNT_CHANNEL_ID:
|
||||
client.loop.create_task(update_stats())
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_guild_join(guild: discord.Guild):
|
||||
# Instant slash commands in the new server
|
||||
try:
|
||||
from utils.slash_sync import sync_guild
|
||||
synced = await sync_guild(client, guild, copy_global=True)
|
||||
print(f"◈ Slash sync for new guild {guild.id}: {len(synced)} command(s)")
|
||||
except Exception as e:
|
||||
print(f"Slash sync on guild join failed: {e}")
|
||||
|
||||
if not LOG_CHANNEL_ID:
|
||||
return
|
||||
log_channel = client.get_channel(LOG_CHANNEL_ID)
|
||||
@@ -155,7 +163,7 @@ async def on_command_completion(context: commands.Context) -> None:
|
||||
|
||||
|
||||
# --- Utility Commands ---
|
||||
@client.command(name='spotify')
|
||||
@client.hybrid_command(name='spotify')
|
||||
async def spotify(ctx: Context, user: discord.Member = None):
|
||||
"""Shows what a user is listening to on Spotify."""
|
||||
user = user or ctx.author
|
||||
@@ -176,7 +184,7 @@ async def spotify(ctx: Context, user: discord.Member = None):
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
|
||||
@client.command(name='makeinvite', aliases=['createinvite', 'makeinv'])
|
||||
@client.hybrid_command(name='makeinvite', aliases=['createinvite', 'makeinv'])
|
||||
@commands.is_owner()
|
||||
async def make_invite(ctx: Context, guild_id: int = None):
|
||||
"""Creates an invite for a specified server (owner only)."""
|
||||
@@ -206,7 +214,7 @@ async def make_invite(ctx: Context, guild_id: int = None):
|
||||
|
||||
|
||||
# --- Webhook Management Commands ---
|
||||
@client.command(name='create_hook', aliases=['makehook'])
|
||||
@client.hybrid_command(name='create_hook', aliases=['makehook'])
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def create_hook(ctx: Context, *, name: str = None):
|
||||
"""Creates a webhook in the current channel."""
|
||||
@@ -228,7 +236,7 @@ async def create_hook(ctx: Context, *, name: str = None):
|
||||
await ctx.send(f"Webhook created: **{webhook.name}**\n||{webhook.url}||\n(I could not DM you the URL.)")
|
||||
|
||||
|
||||
@client.command(name='delete_hook', aliases=['delhook'])
|
||||
@client.hybrid_command(name='delete_hook', aliases=['delhook'])
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def delete_hook(ctx: Context, webhook_url: str = None):
|
||||
"""Deletes a webhook using its URL."""
|
||||
@@ -244,7 +252,7 @@ async def delete_hook(ctx: Context, webhook_url: str = None):
|
||||
await ctx.send(f"{ERROR} Webhook not found or URL is invalid.")
|
||||
|
||||
|
||||
@client.command(name='list_hooks', aliases=['hooks'])
|
||||
@client.hybrid_command(name='list_hooks', aliases=['hooks'])
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def list_hooks(ctx: Context):
|
||||
"""Lists all webhooks in the current channel."""
|
||||
@@ -262,7 +270,7 @@ async def list_hooks(ctx: Context):
|
||||
|
||||
|
||||
# --- Game Command ---
|
||||
@client.command()
|
||||
@client.hybrid_command()
|
||||
async def reaction(ctx: Context):
|
||||
"""See how fast you can react to the correct emoji."""
|
||||
emojis = ["🍪", "🎉", "🧋", "🍒", "🍑", "💸", "🌙", "💕"]
|
||||
|
||||
Reference in New Issue
Block a user