Repository navigation
Conversation
The bot connects only when an admin enables it with a token and a server ID; it registers no commands yet. Installs that never configure Discord load no Discord code and make no Discord connection. - discord.js 14.28.1 (exact), loaded with import() only after the settings say the bot is configured, once per process - Bot lifecycle: one client per process, start/stop/restart safe to interleave (generation counter), Guilds intent only, no mentions parsed by default, client error and shardError listeners, interactions from other servers ignored, an empty command list registered per server - Startup starts the bot in the background; init never waits for Discord - Running-check facade (discord-runtime) for core code: no import while the bot is off, never throws or blocks its caller - Settings: GET/PUT /api/admin/settings/discord (token encrypted and masked, one transaction, bot restarted in the background) and POST /api/admin/settings/test-discord (bot identity, servers, names for the entered IDs, invite link with permissions 84992); IDs validated as snowflakes, Discord paths built with Routes - Discord settings tab: reads RMAB's saved settings on load; Discord is contacted only on Test - Users page: a Discord user ID field (link, unlink) and the linked ID, shown only when the bot is configured Builds on the original #231 commits d5234a1, dc8bdf1, dfcb19e, 829ef04, 489f027, 3db5f10, 555b22d, 54344f6, 4fac28f and b985049 by NichCodes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: NichCodes <90598280+NichCodes@users.noreply.github.com>
…rint spec - documentation/integrations/discord-bot.md: settings keys, lifecycle, router, API, UI, build, downgrade - fake-arr :443 sinkhole records each connection's TLS SNI; the stack aliases send discord.com, gateway.discord.gg, cdn.discordapp.com and discordapp.com there - 231-zero-footprint.spec.ts: bot off = no Discord connection and web flows unchanged; a fake token reaches the sinkhole; disabled = silent again Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ate in effects - useDiscordSettings: one GET on mount in a promise chain (ignored after unmount); the Test body lists its five fields; the unused reload is gone - DiscordAccountField: keyed by user and saved ID instead of an effect that reset its state - tests: no explicit any Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ole) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bounded Test - Discord tab: a failed settings load shows an error with Retry; Test and Save stay off until a load works. After a Save that enables the bot, the status is read up to 5 times (1 s apart) until running or failed. Editing an ID or the token clears the last Test result. Help text says Test still reaches Discord while the bot is off, and asks for an application made only for RMAB with Public Bot off. - Settings PUT: the mask or '' keeps the saved token; only clearBotToken: true removes it. A pasted "Bot " / "Bearer " prefix is dropped on save and on Test. - Bot service: a start destroys a client left by an earlier start before logging in; interactions from a superseded client are ignored. Invalidated, or a shard closed for good (e.g. 4004), sets status failed, clears the running flag and destroys the client (no automatic retry). - Test REST client: a 429 fails at once with a fixed message (429); no sweeper timers; no server lookup when the server list already has it; "not in this server" only on 403/404, otherwise "could not check the server". - Interaction router: from a DM only buttons and select menus pass. - Shutdown: the coordinator stops the bot (peeked state, never loads discord.js) alongside the drain, within one step limit. - One shared snowflake check for the tab, the Users page field and the actor resolver. - Zero-footprint import walk also follows require() and plain template-literal imports, and covers the shutdown coordinator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g token check - discord-bot.md: dedicated application with Public Bot off (connecting replaces its server commands), clearBotToken, 429 / sweepers / server lookup, DM rule, gateway closed for good, shutdown stop, the shared ID check - settings-pages.md, unified.md: load error + Retry, status re-reads, bot stop step - 231 e2e run B: the fake token must be absent from the whole RMAB log; the tab with a failing settings GET shows Retry and no Save or Test (screenshots); cleanup clears the token with clearBotToken Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The settings PUT clears the saved token only when clearBotToken is true and botToken is '' or the mask; a new value is saved even when clearBotToken is set. Tests: the route saves the new token, and the tab never sends clearBotToken with a typed token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
/request, request cards,/status, Cancel and/delete.Discord bot not started) and that is all.src/lib/services/discord/discord-bot.service.ts): started from app init in the background, never waited on, so a slow or unreachable Discord never delays startup. A failed login logsFailed to start the Discord bot, shows the reason on the tab, and never throws. Saving the settings restarts the bot; turning it off stops it.Guildsintent only (no privileged intents),allowedMentions: { parse: [] },error/shardErrorlisteners.src/lib/services/discord/discord-runtime.tsis the only Discord module core code imports. A unit test walks the import graphs (static imports,import()andrequire()) of the request accept/deny, cancel and delete routes, their services, app init and the shutdown coordinator, and fails if discord.js or the bot module appears.clearBotToken). A leadingBotorBeareris dropped on save and on Test.Discord: <id>under their name. Without a configured bot the page is unchanged.GET/PUT /api/admin/settings/discord,POST /api/admin/settings/test-discord.discord.request_card_modereadsdmwhen unset). The setting has no control on the tab yet; it arrives with the cards.documentation/integrations/discord-bot.md(new), settings pages, admin dashboard, scheduler, auth, table of contents, e2e harness.Why
Part 2 of 5 of #231 by @NichCodes, rebuilt on current main. Thanks to NichCodes for the design: the bot service, the settings tab with a connection test and invite link, and the account link on the Users page all follow #231. This part covers the bot-core commits of #231: d5234a1, dc8bdf1, dfcb19e, 829ef04, 489f027, 3db5f10, 555b22d, 54344f6, 4fac28f and b985049. Changes from #231:
Dependency
npm install --save-exact --before=2026-11-04(npm 11, the major that wrote main's lockfile, so no unrelated fields change). Every added entry is therefore at least 14 days old on 2026-11-18. It avoided the newer ws 8.23.0 and discord-api-types 0.38.59.Lockfile diff (checked by script against main: 21 added, 0 removed, 2 changed; every added entry resolves from registry.npmjs.org with an integrity hash):
Changed: the root
dependenciesgaindiscord.js;fast-deep-equal3.1.3 loses its dev flag (now also a runtime dependency), with no version change.Publishers (npm usernames):
Audit:
npm audit --omit=devreports the same 9 advisories on main and on this branch, all in packages already on main. None is in a package this PR adds. Both nested undici copies are 6.29.1 and ws is 8.22.1, at or above every published fix. GitHub lists no advisories for discord.js, @discordjs/rest or @discordjs/ws.Image size: 2,043,060,510 bytes against 2,037,965,105 for main (+5.1 MB, +0.25%).
docker run --rm --entrypoint node <image> -e "import('discord.js').then(m=>console.log(typeof m.Client))"printsfunction, so the standalone build ships discord.js.Checks
npm run test: 653 files, 12032 passed, 9 skipped, 0 failed (local, before the last commit, which adds 2 tests: the route and tab test files pass 32/32). CI on the head: 663 files, 12120 passed, 3 skipped.npx tsc --noEmitandnpx tsc -p e2e --noEmit: clean. ESLint on the changed files: no new findings (the remaining ones are on main already).npm run e2e:selftest: 81/81 (includes the new sinkhole tests: SNI recorded from a TLS hello, empty host for plain TCP).docker compose build readmeabookexits 0 (the compose file's build section is commented out, so it builds nothing); the image itself was built fromdockerfile.unifiedas above.231-zero-footprintran on this branch and on main, and again on the branch after the settings and lifecycle fixes with the same results:Discord bot not startedonce and no other Discord line; nodiscord_user_idset; the Users page dialog has no Discord field (1280 light, 375 dark).POST /cancel(200), admin delete (200, then 404).Initializing application services...to the init route's 200): 4259 ms on the branch, 4260 ms on main.discord.com; the tab shows "Could not connect";Failed to start the Discord botis logged; the token is stored encrypted and appears nowhere in the whole RMAB log; accepting a request on the web still answers 200; the Users page shows the field and theDiscord: <id>line.smokewith default flags: passed on the first branch image, before the settings and lifecycle fixes (request, grab, download, organize, in the library); its log has the singleDiscord bot not startedline and no sinkhole record.Screenshots
From the test stack (fake token and made-up IDs; Discord hosts go to the local sinkhole).
Risk and rollback
discord.*settings, so the bot is simply gone. Turn the bot off first so the old and new images never both use the token. No schema change in this PR.To try it with a real bot
Discord: <id>.🤖 Generated with Claude Code