Skip to content

fix(discord): register slash commands after client is ready#96

Open
webframp wants to merge 2 commits intocalesthio:masterfrom
webframp:fix/discord-slash-command-registration
Open

fix(discord): register slash commands after client is ready#96
webframp wants to merge 2 commits intocalesthio:masterfrom
webframp:fix/discord-slash-command-registration

Conversation

@webframp
Copy link
Copy Markdown

Problem

Slash command registration in lib/alerts/discord.mjs runs before client.login(), so client.user.id is undefined. The fallback || 'me' on line 126 passes the string "me" to Routes.applicationGuildCommands(), which Discord's API rejects:

[Discord] Failed to register slash commands: Invalid Form Body
application_id[NUMBER_TYPE_COERCE]: Value "me" is not snowflake.

This means guild-scoped slash commands never register when DISCORD_GUILD_ID is set. The bot connects fine but /status, /sweep, /brief, etc. don't appear.

Root Cause

Two issues in start():

  1. _registerCommands() was called before client.login(), so client.user didn't exist yet
  2. The ready event listener was attached after await client.login(), which resolves after the gateway READY event — so the listener could miss the event entirely

Fix

  • Move the ready event listener before client.login() so it can't be missed
  • Move _registerCommands() inside the ready handler where client.user.id is guaranteed to be available

Changes

  • 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 Body
After: [Discord] Registered 7 guild slash commands

exe.dev user and others added 2 commits April 20, 2026 04:16
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>
@webframp webframp requested a review from calesthio as a code owner April 20, 2026 04:35
@webframp
Copy link
Copy Markdown
Author

Another issue I hit walking through my bot setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant