Projects · What I'm known for

Relaxy!

Active 2019 – now Creator, sole developer and operator

A sharded, multipurpose Discord bot and everything around it (dashboard, website, status page, CDN), serving 200,000+ users from a single little Raspberry Pi.

3 photos

  • The relaxy.xyz home page
    The relaxy.xyz home page
  • The public uptime page, fed by the health probes
    The public uptime page, fed by the health probes
  • Relaxy herself
    Relaxy herself


Relaxy! started in 2019 as a bot for a couple of servers and grew into a small ecosystem that I design, write and operate alone. It now serves more than 200,000 Discord users, and the whole fleet runs on a single Raspberry Pi with every service isolated under Podman and bubblewrap.

What I built#

The bot runs as a sharded fleet: one supervising manager process and N cluster processes, backed by MongoDB. It has more than 160 public commands and 58 event handlers covering moderation, levelling, an economy, music, image generation, tickets and welcome cards.

  • One moderation pipeline. A ban placed by command, by the dashboard or by a synced partner server lands identically: same case number, same modlog entry, same DM, same appeal invite. Actions taken by hand in the Discord client are read back from the audit log so the case history stays complete.
  • Cross-server links without credentials. Two servers link when the same person runs the same command in both within thirty minutes. That handshake drives ban appeals, role syncing across a pool of servers, and opt-in synced moderation.
  • Scam detection. OCR over posted screenshots plus perceptual hashing, deduplicated by image hash and shared across the fleet.
  • Storage. Diff-based document writes, multi-process database workers and local caching keep MongoDB traffic small.
  • Operations. Hot reload that decides on its own when a change really needs a recluster, rolling restarts, an ADSR watchdog that restarts a shard on sustained errors, and a network watchdog that recognises a fleet-wide outage and holds off respawning until it's over.
How the fleet fits together

There are two kinds of process. One manager per host supervises everything (the console, hot reload, the dashboard API) and never connects to Discord itself. It forks N clusters, and each cluster is a full bot running one or more Discord shards.

Discord's sharding formula puts every server on exactly one shard, so a server lives on exactly one cluster, and only that cluster can act on it. Most of the design follows from that one fact:

  • Anything fleet-wide is a broadcastEval: a function serialised, sent to every cluster and run there. It can close over nothing, so an outer variable isn't a lint warning, it's a ReferenceError on the other side. Every cluster answers, the ones without the server return null, and the caller takes the first real answer.
  • Anything that must happen once, not once per cluster (the support server's log channel, the sweeps that write shared state), belongs to one designated cluster, and the others relay to it over IPC.
  • Relaxy's own IPC message types extend the sharding library's. They're copied into a new table instead of written onto the library's, ever since writing onto it gave two messages the same number and a reshard message started flipping a log channel.

Hot reload works on the same fleet. On a save, the manager tells every cluster to re-import the file: a command or a module is swapped in place, and an event's new listener is imported before the old one comes off, so a broken save leaves the old one running. For a helper file, it reads the import graph from disk and reloads everything between that file and what uses it. It only asks for a full recluster when the change can't be swapped live, like the bot's constructor changing.

How a write reaches MongoDB

Defaults are never stored. Before a document is written, everything still at its default is stripped out, and the defaults are merged back in on read. Adding a field is free (every existing document gains it on its next read, no migration), and a document equal to its defaults isn't stored at all.

A server is two documents: a hot one read on nearly every message (prefixes, censoring, levels, restrictions) and a cold one for everything a config command or a rarer event needs (welcomes, tickets, appeals, modlogs, music). Callers see them merged, and each write is routed back to the half that owns it.

Writes are queued, not sent. A change updates the cached copy straight away, so the next read on that cluster already sees it, then marks the document dirty behind a 200 ms debounce, so a burst of changes is one write. Members and profiles are diffed against the copy last read or written and go out as $set/$unset, with $inc for counters so two increments in flight both count. The actual database I/O runs on a worker thread, off the event loop.

Caches never expire, and any cluster may write any server's document (linked servers do it all the time), so writing someone else's document means flushing it and broadcasting a reload to the whole fleet afterwards.

Riding out a network outage

The network watchdog replaced one that killed every cluster after ten network errors in ten seconds and then slept for half an hour. One September day that turned a degraded bot (requests and the database timing out, but the open gateway sessions still working) into a dead one, respawned it into a network that was still flapping, and left a cluster that then ran out of memory down for good. The new one works by five rules:

  1. Measure, don't infer. It opens fresh connections to Discord's REST edge, the gateway, the database and a couple of control hosts, so "Discord is down", "this box is offline" and "DNS is broken" look different. Error reports from the clusters only make it probe sooner.
  2. Never turn an outage into downtime. Nothing is killed because the network is bad.
  3. Repair one cluster at a time. A cluster that's dead, never logged in, or hasn't reconnected within a budget of healthy-network time is respawned with backoff, spaced from the others.
  4. Never trust the probes absolutely. Past a hard ceiling a cluster is repaired anyway.
  5. Never burn the identify budget. Discord allows about a thousand session starts a day before it resets the token, so a respawn loop could take the whole bot offline on its own.

A link only flips after several results in a row, so one lost packet isn't an outage and one lucky handshake in the middle of one isn't a recovery.

Moderation, in more detail#

  • Hierarchy everywhere. Nobody can act on the owner, the bot, themselves or anyone at or above them, and Relaxy refuses roles and actions above its own position.
  • Cases and dossiers. Every action gets a numbered case, lifting one is recorded as an outcome on the case it lifts, and a member's dossier shows their whole history at a glance.
  • Warnings with tiers. A server sets what happens at each count (a mute, a kick, a ban or a role), fired once as the line is crossed.
  • The censor. Word lists with per-entry exceptions and severities, links, invites (disguised ones too) and a scam detector fed by a vocabulary on the CDN plus built-in signatures.
  • Spam and raids. Spam-shaped text and the same message repeated or posted across channels, the way stolen accounts post, with configurable thresholds; raid protection, and a lockdown that puts back the exact permissions it found.
Why the order of a ban matters

ban, kick, mute, unmute and warn exist once. Commands, the dashboard and synced moderation all call the same code, because a second ban would be a second answer to questions with exactly one right answer: is the case recorded before or after the DM, does the reason go through the censor. The order is different for each action, on purpose:

  • Ban: case, then DM, then ban. The DM has to go out first, because once they're banned Relaxy usually shares no server with them and Discord won't deliver it. The case has to come before the DM so the message can quote the case number.
  • Kick: DM, pending case, kick, case. A kick fires Discord's "member left" event, often before the case is written. Announcing the pending case first lets that event reuse it with the real moderator instead of opening a second one.
  • Mute: save the roles, strip them, record the mute, then the case. Once the strip lands, that list of roles exists nowhere else, and losing it would lose their roles for good.

Who and for how long are parsed once too. The target comes from the leading arguments only (never from mentions inside the reason, or the author of a replied-to message), an ambiguous name is refused, and a bare number only counts as a duration as the first word, so "banned for 3 alts" doesn't become three minutes.

Reading scams out of screenshots

Scam accounts stopped posting text: they post a fake giveaway or a casino "withdrawal success" page with an empty message, and the words a filter would catch live in the pixels. So Relaxy reads them back out and feeds them to the same censor check typed text goes through, which means a domain added to the scam list tomorrow is caught inside images for free.

  • Built for the Pi. It's the native tesseract binary in a child process, not the WebAssembly port: several times faster on ARM, a fraction of the memory, and it never blocks the event loop. Each read gets one thread and at most four run at once, queued behind a semaphore. Screenshots are greyscaled, inverted when they're mostly dark (Tesseract wants dark text on light), contrast-normalised and resized to 1280 px.
  • Remembered by content. A scam posts the same four pictures into every channel it can reach, and every upload gets a fresh link, so images are keyed by a SHA-256 of their bytes. A repeat costs about 10 ms instead of a ~2.3 s read, reads already in flight are joined instead of restarted, and the memory is shared by the whole fleet, because a campaign posting everywhere at once is exactly what spreads its images across clusters. A confirmed scam is remembered for a year and a clean read for 30 days, both measured from last use.
  • Fail-safe. Every failure (no binary, an image that won't decode, a hung read) gives an empty read and the message is judged on its text alone. Only Discord's own CDN is fetched, with an 8-second deadline, a file signature check before anything decodes, and a 50-megapixel cap.

Measured over 2,578 remembered images (635 confirmed scams), it's how a Russian casino advert that used to score 3 against a threshold of 6 now scores 7.

Linked servers#

Two servers are linked by the same person running the same command in both within thirty minutes, holding the right permission in both at every step. A banned member can appeal from a partner server, in a private thread with their dossier; a pool of servers can share roles (existing ones are adopted, never duplicated, and anything with admin permissions is never synced); and synced moderation is one-way and per partner, each server naming who may moderate it and applying the action with its own checks, case number and modlog.

Why the handshake is the security model

There are no tokens, invites or server IDs to paste. The first command records a proposal on the person's profile (the second server has nothing else to recognise the first by), one at a time, expiring after thirty minutes. The second command accepts it, so a link can only exist where one person holds the permission in both servers.

The permission is checked at both steps: when the link completes, the cluster that owns the first server fetches the proposer again and re-checks it, so someone demoted or gone in the meantime gets a refusal. The proposal is used up before anything is written, so it can't be replayed, and it's read straight from the database rather than the cache, because it was written by a different cluster and a cached copy would say nothing is waiting.

The link settings themselves are off limits to the dashboard's ordinary config writes. Otherwise a server admin could map a role they control onto a role in any server Relaxy is in.

Music#

A vendored, patched music player streaming through yt-dlp, with filters, an equaliser, lyrics and prefetching, from YouTube, SoundCloud, Spotify, Apple Music, Bandcamp, Mixcloud, Twitch, Niconico, the Internet Archive and around twenty other sources. Spotify and Apple tracks are matched to the same recording on YouTube before falling back to SoundCloud.

Everything else#

XP from messages and voice with server and global levels, rank cards and level rewards; an economy with a shop, trading, reputation and a card collection; games (snake, minesweeper, tic-tac-toe, counting); welcome and goodbye cards, heartboards, tickets, reaction roles, join-to-create voice channels, reminders and image commands. A garbage collector clears out a server's data 180 days after Relaxy leaves it, and a member's 30 days after they leave.

The dashboard (dashboard.relaxy.xyz) is a Fastify app on Bun with Discord OAuth. Access is computed from the OAuth guilds permission bitfield into four tiers (owner, server admin, moderator, member), each setting needs the same Discord permissions as the command behind it, every write goes through a single choke point against a typed allow-list of fields, and every form carries a per-session CSRF token. No front-end framework, just server-rendered HTML and a little vanilla JS.

The website (relaxy.xyz) is 12 dependency-free pages (~4,600 lines of JS, ~5,850 of CSS) with a changelog, devlog, technical write-up and the public uptime page.

The supporting services (relaxy-additions) keep the Pi alive: a prober that checks 24 services every ten seconds and publishes three JSON feeds, a hardware watchdog on /dev/watchdog, an uptime ledger with incident detection and cause inference mirrored into a Discord channel, an incident CLI, and an nftables table that keeps SSH in priority band 0 at DSCP CS6 so the box stays reachable while it's struggling. A network monitor checks every hop (link, router, ISP, DNS, Cloudflare, Discord) every 15 seconds and names whose fault an outage is, with 90 days of history. Every container runs under its own block of user IDs, fenced off from the LAN, the tailnet and the host, so a break-in to one service stays inside it. And the bot fails over: a standby machine takes it over when the Pi drops off the network or sits frozen without its database, and hands it back when the Pi returns, with a lease in the database making sure two bots never run on one token. The same box runs the ETB speedrun bot in a bubblewrap sandbox.

How it grew#

I first wrote Relaxy in early 2019 for a couple of servers. The code as it is now lives in a repository started in September 2021, and most of it was written from 2023 on: 126 commits that year, 121 the next, 572 in 2025, when it became the fleet described above, and close to 300 more in 2026 so far.

Why it matters#

Running something this size on a single-board computer forced me to care about memory, process isolation, back-pressure and failure modes that a cloud VM would just let me ignore. Most of what I know about operating software in production I learned keeping Relaxy up.

Note

The working source is private. relaxy-public-v2 is a read-only mirror of the bot with the comments, owner tooling and music pipeline stripped, and relaxy-additions and relaxy-website are public too. The dashboard's source is private. The first public showcase is kept as Relaxy! Public v1.

Fan art

Drawn by people who use it. Thank you, all of you.

21 pictures

  • Relaxy! meets Kitty: fan art of Relaxy!
    Relaxy! meets Kitty
  • Relaxy! interacting with the ETB community: fan art of Relaxy!
    Relaxy! interacting with the ETB community
  • Relaxy! as a かわいい girl and a mafia boss guy: fan art of Relaxy!
    Relaxy! as a かわいい girl and a mafia boss guy
  • Relaxy! lover guy: fan art of Relaxy!
    Relaxy! lover guy
  • Relaxy! (as a guy this time): fan art of Relaxy!
    Relaxy! (as a guy this time)
  • Relaxy cybersheet: fan art of Relaxy!
    Relaxy cybersheet
  • Relaxy! anime girl: fan art of Relaxy!
    Relaxy! anime girl
  • Relaxy! anime waifu: fan art of Relaxy!
    Relaxy! anime waifu
  • Relaxy! fighting with Light Nate's friend: fan art of Relaxy!
    Relaxy! fighting with Light Nate's friend
  • Thousand warning stare: fan art of Relaxy!
    Thousand warning stare
  • Relaxy sitting: fan art of Relaxy!
    Relaxy sitting
  • Original Relaxy! Profile Picture: fan art of Relaxy!
    Original Relaxy! Profile Picture
  • Relaxy! Collab: fan art of Relaxy!
    Relaxy! Collab
  • Fan art of Relaxy!
  • Fan art of Relaxy!
  • Fan art of Relaxy!
  • Fan art of Relaxy!
  • Fan art of Relaxy!
  • Fan art of Relaxy!
  • Fan art of Relaxy!
  • Fan art of Relaxy!