I’m working on a Discord bot that has more than 120 slash commands using NEXTCORD and PYTHON. My command structure looks something like this:
@bot.slash_command(name="games")
async def games(ctx: Interaction):
pass
@games.subcommand(name="trivia")
async def gametrivia(ctx: Interaction):
# trivia game logic here
I have multiple command groups set up this way with various subcommands under each one. What I need to do is get a list of all these slash commands and subcommands as command objects so I can access their names and descriptions. Getting other properties would be nice too but not absolutely necessary.
I already tried using get_all_commands() but that didn’t work for me. It only returned the default help command since my bot doesn’t use any prefix-based commands. Is there another method I should be using to fetch slash commands specifically?
Yeah, this tripped me up too when I first ran into it. Slash commands in nextcord get stored separately from regular text commands, which is why you can’t find them the usual way. What fixed it for me was hitting bot.pending_application_commands right after I defined everything but before bot.run(). That grabs the raw command data before it syncs to Discord’s servers. You could also try bot.get_application_command() if you know the specific command names, but that won’t help much for bulk retrieval. Just make sure you’re checking after on_ready fires since command registration happens async. The timing’s weird - I actually had to throw in a small delay sometimes before the commands showed up in the API.
Had the exact same issue building my bot last year. get_all_commands() only works for old prefix commands, not slash commands. For nextcord, use bot.get_all_application_commands() instead - it returns all registered slash commands and subcommands. If it doesn’t work or comes back empty, call it after the bot’s ready. Sometimes commands aren’t fully registered until the bot connects to Discord. You can also check bot.pending_application_commands to see what’s waiting to sync with Discord’s API. If you’re using cogs, try iterating through bot.cogs since each cog stores its own application commands you can access directly.
btw I also found success using the bot.all_application_commands property instead of calling the method. nextcord sometimes stores commands there when other methods fail. Also check your decorators - syntax errors in subcommand definitions will break registration and they won’t show up anywhere.