Skip to content

Ensure handling of Discord slash commands#152

Merged
haydenbleasel merged 11 commits intovercel:mainfrom
PClmnt:codex/discord-slash-commands
Mar 2, 2026
Merged

Ensure handling of Discord slash commands#152
haydenbleasel merged 11 commits intovercel:mainfrom
PClmnt:codex/discord-slash-commands

Conversation

@PClmnt
Copy link
Copy Markdown
Contributor

@PClmnt PClmnt commented Mar 2, 2026

This PR updates the Discord Adapter to allow correctly handling of slash commands in Discord. Previously, slash commands would just be ACK'd and no response would take place. Also, Discord slash commands require defer + editing the original interaction response.

This updates the adapter so that:

  • APPLICATION_COMMAND events are now dispatched to processSlashCommand.
  • First slash response updates @original (PATCH /webhooks/{app_id}/{token}/messages/@original).
  • Subsequent responses use followups (POST /webhooks/{app_id}/{token}).
  • Works for both text and file attachments in slash responses.

There's a question open, and i've left a comment in the code about how we might want to handle nested subcommands:

Test plan

  • Bot receives a Discord slash command, adapter returns deferred ACK (type 5) immediately — should succeed
  • Bot posts first response via event.channel.post(...) after defer — should replace deferred “thinking…” message (PATCH @original)
  • Bot posts a second response in same slash-command flow — should be sent as a follow-up message (POST webhook)
  • Bot posts a slash-command response with file attachments — should succeed via interaction webhook (no channel API fallback)
  • Slash command invoked inside a Discord thread — should resolve deferred response correctly in that thread context
  • Regular non-slash message posting/editing/deleting/reactions continue to work as before

Video

Screen.Recording.2026-03-02.at.09.46.52.mov

Screenshots

image image image

Resolves #131

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 2, 2026

@PClmnt is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@PClmnt PClmnt changed the title feat(discord): correctly handle slash command deferred responses Ensure handling of Discord slash commands Mar 2, 2026
Comment thread packages/adapter-discord/src/index.ts Outdated
Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

The setupDiscordFetchMock function does not handle Discord interaction webhook URLs (/webhooks/{appId}/{token}/messages/@original and /webhooks/{appId}/{token}?wait=true), causing the "should dispatch slash command handlers" test to fail with a NetworkError.

Fix on Vercel

@PClmnt PClmnt marked this pull request as ready for review March 2, 2026 08:07
@haydenbleasel
Copy link
Copy Markdown
Contributor

haydenbleasel commented Mar 2, 2026

Hey @PClmnt! Great work on this PR 🙌 I pushed a few commits on top of yours:

  • Expand subcommand path into event.commandparseSlashCommand now appends subcommand/group names to the command path (e.g. /project issue create), keeping event.text as flat values. This addresses the open question you left in the TODO comment.
  • Fix initialResponseSent race condition — moved the flag set before await so concurrent post() calls don't both try to PATCH @original.
  • Restore unrelated indentation change — reverted the whitespace-only diff in handleComponentInteraction to keep the PR focused.
  • Extract tryPostSlashResponse helper — deduplicates the slash-context check that was repeated in postMessage and postChannelMessage.
  • Fix integration test mock — added interaction webhook route handlers (editOriginal/followUp) to setupDiscordFetchMock so the slash command integration test actually works end-to-end.

Also updated docs.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview, Comment, Open in v0 Mar 2, 2026 9:18pm

@haydenbleasel haydenbleasel merged commit f01b92f into vercel:main Mar 2, 2026
7 checks passed
@PClmnt
Copy link
Copy Markdown
Contributor Author

PClmnt commented Mar 2, 2026

Hey @PClmnt! Great work on this PR 🙌 I pushed a few commits on top of yours:

  • Expand subcommand path into event.commandparseSlashCommand now appends subcommand/group names to the command path (e.g. /project issue create), keeping event.text as flat values. This addresses the open question you left in the TODO comment.
  • Fix initialResponseSent race condition — moved the flag set before await so concurrent post() calls don't both try to PATCH @original.
  • Restore unrelated indentation change — reverted the whitespace-only diff in handleComponentInteraction to keep the PR focused.
  • Extract tryPostSlashResponse helper — deduplicates the slash-context check that was repeated in postMessage and postChannelMessage.
  • Fix integration test mock — added interaction webhook route handlers (editOriginal/followUp) to setupDiscordFetchMock so the slash command integration test actually works end-to-end.

Also updated docs.

Thanks so much for taking the time to sort those issues out and getting this merged though, I really appreciate it! All looks good on my side. 🚢🚢

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.

Discord: onSlashCommand handlers never invoked via HTTP Interactions

2 participants