Build a Discord bot
A Discord bot with /items add and /items list backed by a placeholder model, and /ask answered by a model. A starting point: rename the model, change the commands, and build your bot on it.
What you'll build
What it shows: Checking Discord's Ed25519 signature on every request, a deferred reply inside Discord's three seconds with a job that edits in the answer, a job keyed by the interaction's id, and registering slash commands from an action.
Before you start
- The CLI:
npm i -g @inferencebureau/apps, thenib-apps loginonce. - A Discord server where you can add apps.
Create the app from the recipe
One command creates the app on Inference Bureau and downloads its files into ./my-discord-bot. Web is the default platform, so the recipe id is all it takes.
ib-apps create my-discord-bot --recipe discord-botTour what the recipe loaded
The recipe replaces the starter, keeping the coding-agent guidance. Here's where each piece lives.
| Where | What's there |
|---|---|
web/lib/discord.ts | verifyDiscord checks the public key and the request's age; discordInteraction answers Discord's check, /items, and /ask with a “thinking…” reply and a queued job. |
web/app/api/discord/ | The Interactions Endpoint URL. |
api/lib/commands.ts, api/actions/registerCommands.ts | The commands as Discord takes them, and the action that registers them. Running it again changes nothing. |
api/actions/answer.ts | The job: the model's answer, edited into the first reply through the interaction's token, so no bot token is needed. |
api/models/item/ | The placeholder model, kept per server. |
tests/discord-bot.test.ts | The signature, the commands, a retried /ask and an expired token, with the model mocked and Discord stubbed. |
if (i.data?.name === "ask") {
const question = String(top.find((o) => o.name === "question")?.value ?? "").trim();
// Discord wants the first reply in three seconds: "thinking…" now, and the answer job edits it in.
await api.enqueue("answer", { question, applicationId: i.application_id, token: i.token },
{ dedupeKey: `discord:${i.id}`, retries: 4 });
return { type: DEFERRED_CHANNEL_MESSAGE };
}Check what it set on the app
Nothing to do here: this is what the recipe configured, so you know where to look in Settings later.
anthropic/claude-haiku-5.5 through the ai clientSet its keys
On Settings → Environment variables, for development first:
| Name | Where it comes from |
|---|---|
DISCORD_PUBLIC_KEY | the Discord application's General Information |
DISCORD_APPLICATION_ID | the Discord application's General Information |
DISCORD_BOT_TOKEN | the Discord application's Bot page |
Finish setup
- Create the Discord application, set
DISCORD_APPLICATION_IDandDISCORD_PUBLIC_KEY, and save<app address>/api/discordas its Interactions Endpoint URL - Set
DISCORD_BOT_TOKEN, then run theregisterCommandsaction once - Install the bot to a server with the
applications.commandsscope and try/items add first try
Discord tests the Interactions Endpoint URL when you save it, so set DISCORD_PUBLIC_KEY first. Run registerCommands again whenever you change the commands.
Run it
ib-apps dev syncs both ways while you work and runs the development server.
cd my-discord-bot
ib-apps devTry it end to end
Make it yours
Rename item, change COMMANDS and discordInteraction, run registerCommands, and change the prompt in answer.ts.
See Calling models for the ai client.
ib-apps test runs its tests, then ib-apps deploy sends development to production; set the keys on production first. See Deploys.