Skip to content

fix(discord): recover existing thread on 160004 error#280

Open
saschabuehrle wants to merge 1 commit intovercel:mainfrom
saschabuehrle:fix/discord-thread-160004-recovery
Open

fix(discord): recover existing thread on 160004 error#280
saschabuehrle wants to merge 1 commit intovercel:mainfrom
saschabuehrle:fix/discord-thread-160004-recovery

Conversation

@saschabuehrle
Copy link

Bug

#279createDiscordThread silently fails when Discord returns error code 160004 ("A thread has already been created for this message"), leaving discordThreadId as undefined. The bot then posts a standalone channel message instead of replying in the existing thread.

Fix

Added error recovery inside createDiscordThread for the specific 160004 error code. When Discord reports that a thread already exists for a message, the method now returns the existing thread's ID (which equals the parent message ID in Discord's threading model) instead of letting the error propagate.

This handles all call sites at once — both the webhook handler and the gateway handler benefit from the recovery without needing individual catch-block changes.

Other Discord API errors continue to propagate normally.

Testing

Verified that:

  • NetworkError with "160004" in the message triggers the recovery path
  • The returned thread ID matches the parent message ID (Discord's documented behavior)
  • Non-160004 errors still propagate to callers unchanged

Happy to address any feedback.

Greetings, saschabuehrle

@vercel
Copy link
Contributor

vercel bot commented Mar 21, 2026

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

A member of the Team first needs to authorize it.

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