README
Sayri Gateway Plugin: Discord Bot
This plugin connects any Discord server or direct message (DM) channel to your AI agents in Sayri, the personal AI assistant.
Key Features
- Sayri xui UI (new in v1.2.0): terminal wizard (
sayri-discord wizard) and local browser panel (sayri-discord serve) to configure the token, toggle guests, view and rotate pairing PIN — all decoupled from the daemon. - Conversation memory journal (new in v1.3.0): tasks, proposals and questions sent by authorized members are appended to per-channel Markdown files, so the server conversation survives restarts and can be reviewed later. See Conversation memory journal.
- Flexible Invocation:
- In server channels:
/sayri <message>,!sayri <message>, or mention the bot@SayriBot <message>. - In DMs: Just type your question and the bot will respond.
- Smart Channel Reading & Summarization:
- Ask Sayri to "resume the last messages", "what was said above", or "summarize this channel" -- the gateway fetches recent messages via Discord's REST API and provides full context to the agent.
- Secure Desktop Pairing (OTP):
- Protection against unauthorized access with a 6-digit PIN generated on your desktop.
- Brute-force protection with attempt limits and automatic PIN rotation.
- Multi-Instance & Sandboxing:
- Create multiple bot instances connected to different agents (e.g. Main Sayri, Developer Assistant) with different isolation levels (
LEVEL_0_NO_EXECtoLEVEL_3_HOST_USER). - Zero External Dependencies:
- Pure Python implementation with RFC 6455 WebSockets over native TLS and REST API v10.
Step-by-Step Setup Guide
Step 1: Create the Discord Application & Bot
- Go to the Discord Developer Portal.
- Click
New Applicationin the top right and give it a name (e.g.Sayri Assistant). - In the left sidebar, go to the
Bottab. - Click
Reset Token(or Copy), copy the Bot Token and save it (you'll need it in Sayri).
Step 2: Enable Privileged Gateway Intents (Required!)
- In the same
Bottab, scroll down toPrivileged Gateway Intents. - Enable the following:
MESSAGE CONTENT INTENT(Required for the bot to read/sayri <message>text in channels).SERVER MEMBERS INTENT(Recommended for identifying server users).
- Click
Save Changesat the bottom.
Step 3: Generate the Bot Invitation URL
- In the left sidebar, go to
OAuth2->URL Generator. - Under
SCOPES, check only:
bot
- Under
BOT PERMISSIONS, check:
Send MessagesSend Messages in ThreadsRead Message History(Required for channel summarization)View ChannelsUse External Emojis(Optional)
- Copy the
GENERATED URLat the bottom. - Paste it in your browser and select the Discord server to invite the bot.
Configuration in Sayri, the personal AI assistant
- Open Sayri and click the Settings button.
- Go to the Gateways tab and click
+ Add Gateway. - Fill in the form:
- Platform: Select
Discord Bot Gateway (sayri-gateway-discord). - Instance Name: e.g.
Discord - Main Server. - Linked Agent: Select the agent (e.g.
Sayri Main). - Sandbox Level: Select the security level (e.g.
LEVEL_1_READONLY). - Bot Token: Paste the token you copied in Step 1.
- Click
Create Gateway Instance. The bot will connect immediately.
Pair Your Discord Account
For security, Sayri rejects messages from unknown users until they pair with the desktop:
- In Sayri, on your Discord Gateway card, click
Show Pairing PIN(shows a 6-digit code). - In your Discord server or DM with the bot, type:
/sayri /pair 123456
(Replace 123456 with the PIN shown on your screen.)
- The bot will confirm your account is authorized. You can now chat with Sayri freely!
Available Discord Commands
| Command | Description |
| :--- | :--- |
| `/sayri <question>` | Send a query or request to Sayri. |
| `!sayri <question>` | Alternative prefix to query Sayri. |
| `@SayriBot <question>` | Direct mention to the bot in any channel. |
| `/sayri resume the last messages` | Read recent channel messages and generate a structured summary. |
| `/sayri /pair <PIN>` | Pair and authorize your Discord account with Sayri. |
| `/memory [status\|on\|off\|show]` | Owner only: memory journal status, enable/disable, or show the last entries of this channel. |
| `!memory [status\|on\|off\|show]` | Text-command fallback for `/memory`. |
Conversation memory journal
While Sayri only answers when addressed, the journal is passive: it records what authorized members write — including messages that do not mention the bot — so a channel's decisions and open questions are never lost.
- What is captured: messages classified as task, proposal or question
- Who is captured: the paired owner and, when guest access is enabled,
- Where:
~/.config/sayri/discord_memory/<instance>/channel_<channel_id>.md - What it never does: reply on Discord, call Sayri Core, or modify anything
- Control:
(keyword heuristics, no model call, no blocking).
server members allowed to interact (/guests on). Strangers are never journaled.
(directory 0700, files 0600). The channel id is reduced to digits before becoming a filename, so a crafted identifier cannot escape the directory.
outside its directory — the gateway appends text and moves on.
/memory → status, directory, number of journals
/memory show → last 5 entries of this channel
/memory off → stop capturing (owner only)
/memory on → resume capturing
sayri-discord memory [on|off] # same toggle from the CLI
The journal is on by default. Captured text is stripped of control characters and truncated; the file grows append-only, so rotate or delete the directory at any time without affecting the gateway.
Description
Autonomous Discord Bot Gateway connecting server channels and DMs to Sayri AI Agents with persistent conversation memory (/new), guest access kill switch (/guests), channel summaries (/resume), and OTP desktop pairing.
Security review
92/100✅ Approved by OpenCode AI (OpenCode Agent (opencode.ai) - Score: 92/100): No backdoors, no credential exfiltration, and no destructive commands found. The package implements strong security controls including HMAC-based PIN verification, rate limiting, PIN rotation, strict DM isolation, and a guest access kill switch. Sandbox compliance is maintained — all communication is restricted to the official Discord API and a local UNIX domain socket with no shell injection vectors.