| Filename | Latest commit message | Latest commit date |
|---|---|---|
| workspace | ||
| .gitignore | ||
| bot.mjs | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
strata-discord-bot
Gateway bot (websocket out to Discord) answering from local Strata. No public URL, no port forwarding.
Using it on Discord
- Mention the bot in any channel:
@StrataBot what does serve/server.py do? - Text before/after the mention is the prompt; the mention itself is stripped.
- Bare mention (
@StrataBotalone) prints this in-server help. - Status emoji appear on your post: 👀 seen, 🤔 generating (removed when the answer posts).
- Follow-ups keep context — the last 8 turns in that channel are replayed to the model.
- Replies are chat markdown: bold, italics,
code,blocks, > quotes, ### headings, @mentions. Long answers arrive as several messages (2000-char Discord limit). - It does not answer slash commands, DMs, or un-mentioned messages.
Setup
- discord.com/developers/applications → your Application → Bot tab: copy token, enable the Message Content toggle (without it
messageCreatenever fires). - OAuth2 → URL Generator: scope
bot, permissionsSend Messages+Read Message History, open the generated URL, invite to your server. npm i discord.js(already done here).echo 'DISCORD_TOKEN=***' > .env— mode 600, gitignored. Never in code, never in chat; rotate if pasted.STRATA_URL/STRATA_MODELin the same file:
STRATA_URL=http://127.0.0.1:8090
STRATA_MODEL=qwen3.8-flash-next-coder-iq1_m
Get the real values from curl -s localhost:8090/v1/models | jq -r '.data[].id' — the model id, not a friendly name.
Backend
Plain OpenAI-compatible call to Strata (/v1/chat/completions) — no agent process, nothing else to run. Per message the bot sends: system prompt (Discord rules + workspace state), last 8 turns of that channel, then the mention text. Images attached to the message go in as vision parts (the model is multimodal, ≤2 images, ≤8 MB each).
Replies
- Real code blocks become attachments (
code1.python…), one message, never chunked. - Blocks tagged
text/md/markdown/plainstay inline — the model is told to keep prose outside fences. - Control blocks (
memory/user/soul/agents) are consumed by the bot and never shown; the reply ends with📝 updated MEMORY.md. - 👀 / 🤔 reactions mark seen/generating. If they never appear, the bot role lacks Add Reactions — grant it in Server Settings → Roles.
- Replies never ping anyone (
allowedMentions.parse = []), so the bot cannot tag itself or start a mention storm. - Another bot that mentions us gets answered too, up to 3 hops per channel; a human message resets the count.
@namemarkup is read as "@Name" / "@Name (bot)" so the model knows who is talking. - Attached images are read as vision input; GIFs/stickers/videos are ignored.
@StrataBot note <text>appends a timestamped bullet toworkspace/MEMORY.mdwithout a model call.- Replies never ping anyone (
allowedMentions.parse = []), so the bot cannot tag itself or start a mention storm. - Another bot that mentions us gets answered too, up to 3 hops per channel; a human message resets the count.
@namemarkup is read as "@Name" / "@Name (bot)" so the model knows who is talking. - Attached images are read as vision input; GIFs/stickers/videos are ignored.
@StrataBot note <text>appends a timestamped bullet toworkspace/MEMORY.mdwithout a model call.
Workspace (bot state)
workspace/ holds the bot's own markdown, re-read on every message and pasted into its system prompt (last 2000 chars each):
| file | meaning | how it changes |
|---|---|---|
SOUL.md |
who the bot is | model rewrites it via a ```soul block |
AGENTS.md |
how it behaves | model rewrites it via a ```agents block |
MEMORY.md |
facts learned on the server | model appends ```memory bullets; @Bot note <text> appends too |
USER.md |
who the humans are | model appends ```user bullets |
Runtime edits dirty the repo (git status) — commit when you agree with them; the bot cannot touch any other path.
@StrataBot search <query>searches the web via SearXNG (SEARXNG_URLin.env, defaulthttps://searxng.cyfrowynomada.com) and answers with cited sources. Requiresformats: [html, json]in the instance'ssettings.yml— without it the API 403s and the bot says so.
Security & robustness
- Token only via
.env(mode 600, gitignored); bot exits loudly if missing. Never in code or chat — rotate if exposed. - Replies carry
allowedMentions.parse: []— the bot can never ping anyone, so no mention storms. - One guard around the whole message handler plus client/shard/unhandled-rejection logging: a bad message logs an error, it never kills the process.
- Model calls and image fetches are timeout-bounded (180 s / 30 s);
noteinput capped at 280 chars; image attachments capped at 2 × 8 MB. - Channel content is treated as data, not instructions (stated in the system prompt); workspace/*.md are the only files it can touch, all paths derive from its own directory.
Service
~/.config/systemd/user/strata-bot.service — Restart=on-failure, RestartSec=3.
systemctl --user restart strata-bot.service # after editing .env or bot.mjs
systemctl --user status strata-bot.service
journalctl --user -u strata-bot.service -f # live log
Unit needs an absolute node path (/home/llama/.local/share/mise/installs/node/latest/bin/node) — systemd's PATH does not contain the mise shim.