Repository navigation
Register slash commands automatically at bot startup - #54
Conversation
Registration was manual-only (npm run register), which left a trap: a guild authorized after the last run -- or authorized without the applications.commands scope, where registration itself fails with 50001 Missing Access -- has the runtime allowlist open but no commands registered, and nothing surfaces it. Live case: the home server's re-authorization granted the scope, but commands stayed invisible because nobody could run the script from a phone. The registration loop moves to src/register.ts, shared by startup and the script. Startup awaits it before login (idempotent PUT per allowed guild, so every deploy converges commands with the code) and treats failure as log-and-continue: a Discord API blip must not keep the gateway down, and npm run register remains the manual lever. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UxahiFZLtf5tER2MuEo9Bo
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c39c085951
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codex P2 on #54, valid: a rejection from one guild (e.g. 50001 Missing Access) exited the loop, leaving every later allowlisted guild with stale or absent commands. Each guild now registers inside its own try/catch; failures log per guild and surface once as an aggregate error, so npm run register still exits non-zero and startup still logs the problem while reachable guilds stay in sync. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UxahiFZLtf5tER2MuEo9Bo
| // manual recovery lever. Await it so a registration burst can't race | ||
| // the first interactions after login. | ||
| try { | ||
| await registerCommands(config) |
There was a problem hiding this comment.
Gateway login waits for cumulative guild registration time
main() awaits registerCommands(config) before calling client.login(), while registration sends each guild request serially. A slow Discord REST failure or retry for every allowlisted guild therefore delays gateway connection by the combined duration, leaving the bot unavailable until the full registration loop settles. Start registration as best-effort asynchronous work with rejection logging, then begin gateway login without waiting for every registration attempt.
Artifacts
Gateway login waited for three slow guild registrations
- Executed the authored startup harness against the original await-based path and shows login occurred only after two failed and one successful slow registration settled.
Original startup source with awaited command registration
- Captured the executed source excerpt showing `await registerCommands(config)` at original line 117 before `client.login`.
Authored focused startup ordering test source
- Captured the authored test harness that runs real startup and registration control flow with three delayed simulated guild REST responses.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: bot/src/index.ts
Line: 117
Comment:
**Gateway login waits for cumulative guild registration time**
`main()` awaits `registerCommands(config)` before calling `client.login()`, while registration sends each guild request serially. A slow Discord REST failure or retry for every allowlisted guild therefore delays gateway connection by the combined duration, leaving the bot unavailable until the full registration loop settles. Start registration as best-effort asynchronous work with rejection logging, then begin gateway login without waiting for every registration attempt.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Registration was manual-only (
npm run register), which left a trap: a guild authorized after the last run — or authorized without theapplications.commandsscope, where registration itself fails with 50001 Missing Access — has the runtime allowlist open but no slash commands registered, and nothing surfaces it. Live case today: the home server's re-authorization granted the missing scope, but commands stayed invisible because nobody could run the script from a phone.Changes
bot/src/register.ts(new): the registration loop extracted into a shared module — one idempotent PUT of the full command set per guild inallowedGuildIds.bot/src/index.ts: startup awaitsregisterCommands(config)before login, so every deploy converges the registered commands with the code. Failure is log-and-continue by design: a Discord API blip must not keep the gateway down.bot/scripts/register-commands.ts: now delegates to the shared module;npm run registerremains the standalone manual lever.bot/src/__tests__/register.test.ts(new): pins one PUT per allowed guild with the configured credentials, and that API failures propagate to the caller (who decides fatality).Verification
Bot suite: 482 tests across 37 files, typecheck clean.
On merge
The bot's Railway service (watch
bot/**, branchmain) redeploys automatically; the boot log will show[bot] Registered N command(s) to guild …and slash commands appear in the authorized server immediately.🤖 Generated with Claude Code
https://claude.ai/code/session_01UxahiFZLtf5tER2MuEo9Bo
Generated by Claude Code
Greptile Summary
This change moves guild slash-command registration into shared startup code so configured guilds are synchronized whenever the bot starts. A reproduced startup failure remains in
bot/src/index.ts: gateway login waits for every serial guild registration attempt to finish, so slow Discord REST failures or retry windows can keep the bot unavailable for their combined duration.The startup registration should run independently of gateway login while retaining its aggregate error logging and the manual recovery command.
Confidence Score: 4/5
The change should not merge until gateway login is decoupled from slow command-registration requests.
A focused executable harness exercised the original startup path with delayed successful and failed guild registrations, and directly observed gateway login occur only after all serial requests settled.
Files Needing Attention:
bot/src/index.tsneeds its startup ordering changed so command synchronization cannot blockclient.login().What T-Rex did
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "Isolate per-guild registration failures" | Re-trigger Greptile