Discord Integration
Status: Implemented. Follow-ups are listed at the end. Tracking: none open. #635 was closed as a duplicate of #1003, but #1003 shipped only the outbound connector below, so the inbound half had no issue.
Why this matters
Today GAIA can post to Discord, but you can’t talk to GAIA from Discord. Themcp-discord connector (#1003) gives the agent tools to read and send channel messages
when you ask it to from the TUI or Agent UI. There’s no way to DM GAIA from your phone and
have it answer from your desktop. This plan builds that bridge and sets it up from both
apps. You paste one token, and nothing needs a terminal command.
What the user gets
You DM the GAIA bot. The flagship agent answers from your PC:- It posts each answer whole; a placeholder names the tool in use meanwhile.
- It sends back files it writes, screenshots and images it makes, and any file you ask for.
- help, new chat, retry (after an expired approval) and Discord’s Reply work in the DM.
- Before any shell command, file write or code execution, it shows Allow / Always / Deny buttons.
/discord setup, or Agent UI Settings → Messaging → Discord):
- Create an application in the Developer Portal and copy its bot token. Discord has no manifest or pre-filled URL, so this step can’t be automated.
- Paste the token. GAIA checks it, stores it in the OS keyring, and starts the bridge in pairing mode with a one-time code shown only on this PC.
- Add the bot to a server you’re in, using the invite link GAIA builds. It needs no
permissions (
permissions=0). Discord only lets you DM a bot you share a server with. - DM the code to the bot. Whoever sends it becomes the only person the bot answers. That proves you are at this PC and control that Discord account. It works the same for apps owned by a team, and an ownership transfer changes nothing. The code lasts an hour, and five wrong guesses replace it.
DIRECT_MESSAGES, and Discord
delivers DM content without Message Content. So there’s no Developer Portal toggle, and
close code 4014 can’t happen. If Public Bot is on (the default), setup warns that anyone
can add the bot to a server and DM it. Those strangers only ever get one refusal.
Decisions
Rules (each one pinned by a test)
- Gateway only. An outbound WebSocket. Buttons arrive as
INTERACTION_CREATEbecause no Interactions Endpoint URL is set. No inbound port and no public URL. - DM-only. Accept only DM channels (no
guild_id). Drop messages from any bot, including this one. Never run an edit (MESSAGE_UPDATE): a message edited after approval must not run again. A recent edit gets one line saying so, so a fixed typo is not a dead end. - Nothing stale runs. A message or click older than 2 minutes (by its snowflake timestamp) is never executed. That covers Gateway RESUME replays and a PC waking from sleep. The bridge says it missed the message and asks for it to be resent.
- One allowed user. Check it on every message and every button press. Refusals go to an audit log at WARNING. A stranger gets one reply saying they’re not authorized.
- Bypass is unreachable.
AgentChannelhas nobypassverb. - Approvals:
- acknowledge each click immediately, with a deferred update, inside Discord’s 3-second window;
- accept a click only on a prompt message the bridge recorded, in the owner’s DM, from the
owner. The confirm ID comes from the bridge’s map, never from
custom_id; - no
confirm_idfrom the agent → deny, and show no buttons; - “Always” appears only when the agent sends an
always_scope; - the command shown can’t be disguised. Backticks are neutralized, bidi and zero-width characters are made visible, and a long command shows its start, end and length, with the full text attached as a file;
- a click on an unknown or answered prompt gets a private “expired” reply and is never forwarded;
- an unanswered prompt is denied after 10 minutes;
- on shutdown, pending prompts are edited to “Expired — bridge stopped.”
- Attachments: only
cdn.discordapp.com/media.discordapp.netover https, no redirects, a size cap, and the filename sanitized into~/.gaia/discord/inbox/(including Windows reserved names,:streams and trailing dots). Every message is sent withAllowedMentions.none(). Uploads come only from a write tool’s path under the upload roots, within Discord’s 10 MB limit. - Reading doesn’t ask. The allowed user can read what the agent can read. Setup says so.
Concurrency
discord.py runs on one dedicated asyncio thread. The adapter core is synchronous, as in
Slack:
- Agent events arrive on the bridge’s reader thread. They call the transport, which
runs a coroutine on the loop (
run_coroutine_threadsafe(...).result(timeout)). That keeps the edits to one message in order. - Inbound handlers run on the loop. They hand work to an executor so a blocked pipe write can’t stall the heartbeat.
- Calling the transport from the loop thread raises instead of deadlocking.
Failure states
Surfaces
- CLI
gaia discord:setup | connect | start [--detach] | stop | restart | pair | autostart | status [--json] | decline | disconnect, pluswatches,watchandunwatchfor GitHub alerts. It owns every rule.connectreads the token from stdin, never argv. - Start:
start --detachspawns throughpopen_outliving_jobwithbackground_popen_kwargs: a hidden console, neverDETACHED_PROCESS, and outside the TUI’s or Electron’s job object so closing them doesn’t kill it. While it imports, the status file names the child’s pid, so a slow start reads “starting”, not “stopped”. - TUI
/discord: setup panel with a masked token prompt,connect, the invite link, thenstart --detach./discordshows status,/discord stop, and the one-time offer. It never prints a command for the user to run. - Agent UI: Settings → Messaging → Discord card. Disconnected → steps and a token
field. Connected → owner, state, invite link, Start/Stop, Disconnect. Router
/api/messaging/discord/*calls the same Python functions. Every failure state has a button. The token and pairing routes requirerequire_local_pc, so a tunnel session can’t swap in its own bot and approve its own commands.
Summaries and alerts
The user asks in plain words (“summarize my PRs every few hours; tell me right away when someone else comments”). Theautomations skill turns that into gaia automation
commands through the agent’s shell tool. Each change shows the user an Allow prompt; the
gaia entry in the skill binary policy allows only the list commands without asking, and
refuses every other gaia subcommand.
- Alerts are not a prompt.
watchregisters a repo and the user’s own accounts. The bridge polls GitHub (issues, issue comments, review comments) every 2 minutes with the gh CLI’s token (10 minutes per watched repo without one) and DMs each new item from anyone else who is not a bot, once, with a link. The first check only records where to start; a repo GitHub won’t show is refused atwatch; three failed checks in a row are reported. - Summaries are.
schedule-addstores a prompt and an interval (at least 5 minutes, at most 10 schedules). On each tick the bridge runs due prompts through its own agent, told the exact UTC window it covers, and posts the answer as a new message, so the phone is notified. A slot missed while the PC was off runs once on return. - Answers are posted whole. Token streaming is off: models think aloud in the same stream, and an edit never notifies. The placeholder only names the tool in use; status text is never echoed. Link previews are suppressed.
- Only the lease holder runs schedules and watches.
Tests
- Unit:
- allowlist and DM-only filtering;
- bot-author drop;
- refusal audit;
- click from a non-owner, stale click, timeout deny, expire-on-close;
- splitting;
- attachment host and redirect refusal;
- lock and status file;
- pairing (code, expiry, guess limit, team-owned app);
- stale-message and stale-click refusal;
MESSAGE_UPDATEignored;- approval text that can’t be disguised;
- lease takeover;
- bot-ID collision refusal;
- local-only routes;
- no bypass anywhere.
- Contract: the transport’s conversion of
discord.pymessages, the intents it requests, and the absence of an edit handler. - Policy: the
gaiabinary policy pinned at all three tiers, and theautomationsskill in the starter-pack checks. - TUI: Go tests for the panel, status and offer, plus the palette and help overlay.
- Agent UI: component tests for the card states (including “starting” while a start is in flight), and router tests for the local-only and CSRF guards.
- Live: a real bot on DeepSeek via Fireworks, starting from no token stored. DM from a phone, approve one shell command, deny one, receive a file, restart the bridge while a prompt is pending, revoke the token.
- Eval: the bridge adds no tool, but the new skill’s description joins the agent’s skill
catalog. Watch
gaia_skills_lifecycleandgaia_shellon the next RC.
Follow-ups (not in this change)
gaia killandgaia uninstallshould stop a running bridge, since a running Python process holds the venv during an upgrade. Todaydisconnector Stop in the apps does it.- Importing
gaiatakes 10–15 s, so a bridge start takes ~30 s. Startup work, not specific to Discord. - Slack ships
slack-sdkonly as an extra, so/slackfails on app installs. Its TUI also printsgaia slack start …for the user to run. - A daemon “messaging service” supervisor for both bridges: start at login, restart with backoff.
- Server-channel mentions and multiple users. Both need a design for per-user agents and histories.
Out of scope
Voice and slash commands. Scheduled briefs to Discord belong togaia schedule’s delivery targets.