Prerequisites
- Node.js 18+
- pnpm (or npm/yarn)
- A Discord server where you have admin access
- A Redis instance for state management
Create a Nuxt app
Scaffold a new Nuxt project and install Chat SDK dependencies:Terminal
Create a Discord app
- Go to discord.com/developers/applications
- Click New Application, give it a name, and click Create
- Go to Bot in the sidebar and click Reset Token — copy the token, you’ll need this as
DISCORD_BOT_TOKEN - Under Privileged Gateway Intents, enable Message Content Intent
- Go to General Information and copy the Application ID and Public Key — you’ll need these as
DISCORD_APPLICATION_IDandDISCORD_PUBLIC_KEY
Set up the Interactions endpoint
- In General Information, set the Interactions Endpoint URL to
https://your-domain.com/api/webhooks/discord - Discord will send a PING to verify the endpoint — you’ll need to deploy first or use a tunnel
Invite the bot to your server
- Go to OAuth2 in the sidebar
- Under OAuth2 URL Generator, select the
botscope - Under Bot Permissions, select:
- Send Messages
- Create Public Threads
- Send Messages in Threads
- Read Message History
- Add Reactions
- Use Slash Commands
- Copy the generated URL and open it in your browser to invite the bot
Configure environment variables
Create a.env file in your project root:
.env
Create the bot
Createserver/lib/bot.ts with a Chat instance configured with the Discord adapter. This bot uses AI SDK to answer support questions:
server/lib/bot.tsx
The file extension must be
.tsx (not .ts) when using JSX components like Card and Button. Make sure your tsconfig.json has "jsx": "react-jsx" and "jsxImportSource": "chat".onNewMention fires when a user @mentions the bot. Calling thread.subscribe() tells the SDK to track that thread, so subsequent messages trigger onSubscribedMessage where AI SDK generates a response.
Create the webhook route
Create a server route that handles incoming Discord webhooks:server/api/webhooks/[platform].post.ts
POST /api/webhooks/discord endpoint. The waitUntil option ensures message processing completes after the HTTP response is sent.
Set up the Gateway forwarder
Discord doesn’t push messages to webhooks like Slack does. Instead, messages arrive through the Gateway WebSocket. The Discord adapter includes a built-in Gateway listener that connects to the WebSocket and forwards events to your webhook endpoint. Create a route that starts the Gateway listener:server/api/discord/gateway.get.ts
Test locally
- Start your development server (
pnpm dev) - Trigger the Gateway listener by visiting
http://localhost:3000/api/discord/gatewayin your browser - Expose your server with a tunnel (e.g.
ngrok http 3000) - Update the Interactions Endpoint URL in your Discord app settings to your tunnel URL (e.g.
https://abc123.ngrok.io/api/webhooks/discord) - @mention the bot in your Discord server — it should respond with a support card
- Reply in the thread — AI SDK should generate a response
- Click Escalate to Human — the bot should post an escalation message
Add a cron job for production
The Gateway listener runs for a fixed duration. In production, set up a cron job to restart it automatically. If you’re deploying to Vercel, add avercel.json:
vercel.json
CRON_SECRET environment variable in production.
Deploy to Vercel
Deploy your bot to Vercel:Terminal
DISCORD_BOT_TOKEN, DISCORD_PUBLIC_KEY, DISCORD_APPLICATION_ID, REDIS_URL, ANTHROPIC_API_KEY). Update the Interactions Endpoint URL in your Discord app settings to your production URL.
Next steps
- Cards — Build rich interactive messages with buttons, fields, and selects
- Actions — Handle button clicks, select menus, and other interactions
- Streaming — Stream AI-generated responses to chat
- Discord adapter — Full configuration reference and Gateway setup