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?