Discord bot, 2026
Jarvis
Private, made for friends
An AI bot on my friends' Discord server. You write @Jarvis in a channel and it replies in character, after reading the last few hours of the conversation and any photos in it. It runs entirely on Cloudflare's free plan: a Durable Object keeps the Discord gateway connection open, and D1 holds a copy of the channel, the history and the group's shared notes.
Why I built it
I wanted a bot for our Discord that knows the people in it and the group's in-jokes, can join a conversation that's already going on, and costs close to nothing to run.
What it does
- Write @Jarvis in a channel, or use /jarvis ask in a group chat or DM. It answers in Polish, in character, as a reply to the message.
- On channels where it's switched on, it reads the last hours of the conversation first, including edits and deletions.
- It sees photos: up to four from a message it's asked about, or one attached to the question.
- The group keeps shared notes ("lore") that go into every prompt, and I can give it separate rules for how it treats a specific person.
- Only people on an access list can use it. Owner-only commands are blocked in code, because Discord can't hide them in group chats.
How it's built
A Cloudflare Worker receives Discord interactions and verifies their Ed25519 signature. Discord expects an answer within 3 seconds and the model takes longer, so the Worker defers the reply and finishes the OpenRouter call in the background. Mentions need a live gateway connection, which a Worker can't hold, so a Durable Object keeps one open, uses alarms as the heartbeat and resumes the session after a deploy. Channel messages are fetched over REST when someone asks and compared with a copy in D1. The prompt is ordered for caching: no clock time in the system prompt, per-person rules at the very end, and a history window that moves in jumps, so its beginning stays the same between questions.
Where it is now
It runs 24/7 on Cloudflare's free plan. Replies written under one person's rules are hidden from everyone else's history, so that tone doesn't spread to other people.
Stack
- TypeScript
- Cloudflare Workers
- Durable Objects
- D1
- Discord Gateway
- OpenRouter