A production-ready Discord AI chatbot powered by GROQ (llama-3.1-8b-instant), built with Express.js and the Discord Interactions API (slash commands over HTTP — no WebSocket required).
/ask:Explain recursion simply
- User types
/ask:<anything>in Discord - Discord sends an HTTP POST to your server's
/interactionsendpoint - The server immediately responds with a deferred response (type 5) → Discord shows "Bot is thinking…"
- The server asynchronously calls GROQ API to get the AI response
- The server PATCHes the original deferred message with the AI reply
This architecture means the server only needs to be alive when Discord is actively sending a request — perfect for Render free tier.
neurocord/
├── src/
│ ├── index.js # Express server & interaction router
│ ├── verify.js # Discord request signature verification
│ ├── groq.js # GROQ Chat Completions client
│ ├── discord.js # Follow-up message helpers
│ └── commands/
│ └── ask.js # /ask command handler
├── scripts/
│ └── register.js # One-time slash command registration
├── .env.example # Environment variable template
├── render.yaml # Render deployment config
└── package.json
- Go to Discord Developer Portal
- Click New Application → give it a name (e.g., "NeuroCord")
- Navigate to General Information and copy your Application ID and Public Key
- Navigate to Bot → click Add Bot → copy the Bot Token
- Under Bot → Privileged Gateway Intents, enable what you need (none required for slash commands)
- Go to console.groq.com
- Sign up / log in → API Keys → Create API Key
- Copy the key
cp .env.example .envFill in .env:
DISCORD_PUBLIC_KEY=<from Discord Developer Portal → General Information>
DISCORD_BOT_TOKEN=<from Discord Developer Portal → Bot>
DISCORD_APPLICATION_ID=<from Discord Developer Portal → General Information>
GROQ_API_KEY=<from console.groq.com>
PORT=3000
npm installRun this once to register the slash command with Discord:
npm run registerOutput:
✅ Registered 1 command(s):
/ask — Ask the AI anything!
Note: Global commands can take up to 1 hour to propagate. For instant testing, add a
DISCORD_GUILD_IDto.envand modifyscripts/register.jsto use the guild-scoped endpoint.
npm start
# In another terminal:
npx ngrok http 3000Copy the ngrok HTTPS URL (e.g., https://abc123.ngrok.io).
- In Discord Developer Portal → your app → General Information
- Paste your URL +
/interactionsinto Interactions Endpoint URL- e.g.,
https://abc123.ngrok.io/interactions
- e.g.,
- Click Save Changes — Discord will send a PING. If the endpoint is valid, it saves successfully.
- Push this repo to GitHub
- Go to render.com → New Web Service → connect your repo
- Render auto-detects
render.yamland configures the service - In Environment, add your secret values:
DISCORD_PUBLIC_KEYDISCORD_BOT_TOKENDISCORD_APPLICATION_IDGROQ_API_KEY
- Deploy — copy your Render URL (e.g.,
https://neurocord.onrender.com) - Set Interactions Endpoint URL to
https://neurocord.onrender.com/interactions
Render free tier note: The service will sleep after 15 minutes of inactivity. It wakes automatically when Discord sends the next interaction — no keep-alive needed since Discord retries.
In Discord Developer Portal → OAuth2 → URL Generator:
- Scopes:
bot,applications.commands - Bot Permissions:
Send Messages
Copy the generated URL, open it in a browser, and add the bot to your server.
/ask:What is the meaning of life?
/ask:Write a Python function to reverse a string
/ask:Explain quantum entanglement in simple terms