Discord bot slash commands not working - timeout error

Hey everyone! I’m having issues with my Discord bot and slash commands. Every time I try to use a slash command, I get “The application did not respond” error message. Regular events like messages and reactions work fine, but slash commands just don’t trigger at all.

I’ve tried coding this in both JavaScript and Python but same problem happens. The bot has admin permissions and I’ve synced the commands properly. Here’s my Python code:

import discord
from discord import app_commands
from discord.ext import commands

with open("config.txt", "r") as file:
    bot_token = file.readline().strip()

class MyBot(commands.Bot):
    async def on_ready(self):
        try:
            server = discord.Object(id=1234567890123456789)
            result = await self.tree.sync(guild=server)
            print(f"Commands synced to server {server.id}")
        except Exception as error:
            print(f"Sync failed: {error}")
        print(f"Bot ready as {self.user}")
    
    async def on_message(self, msg):
        if msg.author == self.user:
            return
        if msg.content.startswith('hi'):
            await msg.channel.send(f"Hi there {msg.author.mention}")

intents = discord.Intents.default()
intents.message_content = True
bot = MyBot(intents=intents, command_prefix="$")

SERVER_ID = discord.Object(id=1234567890123456789)

@bot.tree.command(name="greet", description="Bot says hello", guild=SERVER_ID)
async def hello_command(interaction: discord.Interaction):
    print("Command triggered!")
    await interaction.response.send_message("Hello there!")

bot.run(bot_token)

The print statement never shows up which means the command handler isn’t being called. Has anyone faced this before? What am I missing here?

I hit this exact issue when I started with Discord bots. You’re mixing commands.Bot and app_commands but not handling the interactions right. Your slash commands are defined but there’s no interaction handling.

Try await self.tree.sync() without the guild parameter first - this syncs globally. Wait about an hour for Discord to update the commands. Global commands take longer but they’re way more reliable for testing.

If you need guild-specific commands, make sure you’re testing in the server that matches your SERVER_ID. Also, add some error handling around the interaction response - you might have silent exceptions happening.

also, check if your bot has the right permissions in the server. sometimes it helps to remove and re-invite it with the correct scopes and permissions. that could solve your issue!

Had this exact issue last month - it’s a syncing problem with guild commands. Your code looks fine, but there’s a timing issue. You’re syncing in on_ready, but command registration happens after the bot starts. Try this: move your command definition before bot.run() and add a small delay in on_ready before syncing. Also double-check your server ID matches what you’re using in both the sync call and guild parameter. I copied the wrong ID once and it synced to a completely different server. One more thing - make sure you’re testing in the right server. Guild commands only work in the specific server they’re synced to.