fix(discord): register slash commands after client is ready#96
Open
webframp wants to merge 2 commits intocalesthio:masterfrom
Open
fix(discord): register slash commands after client is ready#96webframp wants to merge 2 commits intocalesthio:masterfrom
webframp wants to merge 2 commits intocalesthio:masterfrom
Conversation
The custom .env parser did not handle quoted values, causing passwords and API keys containing special characters (|, ^, ", >, [, etc.) to include the quote characters as part of the value or parse incorrectly. This adds quote stripping for both single and double-quoted values, matching the behavior of dotenv and other standard .env parsers. Co-authored-by: Shelley <shelley@exe.dev>
Slash command registration was called before client.login(), so client.user.id was undefined and fell back to the string "me", causing a Discord API error: Invalid Form Body application_id[NUMBER_TYPE_COERCE]: Value "me" is not snowflake. This moves command registration into the ready event handler and attaches that handler before login() to avoid a race condition where the ready event fires before the listener is attached. Co-authored-by: Shelley <shelley@exe.dev>
Author
|
Another issue I hit walking through my bot setup |
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.
Problem
Slash command registration in
lib/alerts/discord.mjsruns beforeclient.login(), soclient.user.idisundefined. The fallback|| 'me'on line 126 passes the string"me"toRoutes.applicationGuildCommands(), which Discord's API rejects:This means guild-scoped slash commands never register when
DISCORD_GUILD_IDis set. The bot connects fine but/status,/sweep,/brief, etc. don't appear.Root Cause
Two issues in
start():_registerCommands()was called beforeclient.login(), soclient.userdidn't exist yetreadyevent listener was attached afterawait client.login(), which resolves after the gatewayREADYevent — so the listener could miss the event entirelyFix
readyevent listener beforeclient.login()so it can't be missed_registerCommands()inside thereadyhandler whereclient.user.idis guaranteed to be availableChanges
lib/alerts/discord.mjs: Reordered event listener registration and command setup (no logic changes, just ordering)Testing
Before:
[Discord] Failed to register slash commands: Invalid Form BodyAfter:
[Discord] Registered 7 guild slash commands