Discord bot
Apps/Recipes/Discord bot

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.

Web, no sign-inKind backendRecipe id discord-bot

What you'll build

Discord/items or /askSigned route"thinking…" within 3sanswera job, once per interactionReplyedited in

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, then ib-apps login once.
  • 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-bot

Tour what the recipe loaded

The recipe replaces the starter, keeping the coding-agent guidance. Here's where each piece lives.

WhereWhat's there
web/lib/discord.tsverifyDiscord 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.tsThe commands as Discord takes them, and the action that registers them. Running it again changes nothing.
api/actions/answer.tsThe 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.tsThe 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.

PlatformWeb, no sign-in
Modelanthropic/claude-haiku-5.5 through the ai client

Set its keys

On Settings → Environment variables, for development first:

NameWhere it comes from
DISCORD_PUBLIC_KEYthe Discord application's General Information
DISCORD_APPLICATION_IDthe Discord application's General Information
DISCORD_BOT_TOKENthe Discord application's Bot page

Finish setup

  1. Create the Discord application, set DISCORD_APPLICATION_ID and DISCORD_PUBLIC_KEY, and save <app address>/api/discord as its Interactions Endpoint URL
  2. Set DISCORD_BOT_TOKEN, then run the registerCommands action once
  3. Install the bot to a server with the applications.commands scope 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 dev

Try it end to end

0 of 2 checked

Make it yours

Your bot

Rename item, change COMMANDS and discordInteraction, run registerCommands, and change the prompt in answer.ts.

Calling models

See Calling models for the ai client.

Ship it

ib-apps test runs its tests, then ib-apps deploy sends development to production; set the keys on production first. See Deploys.