fix(discord): ensure autoThread replies route to existing threads

Fixes #8278

When autoThread is enabled and a thread already exists (user continues
conversation in thread), replies were sometimes routing to the root
channel instead of the thread. This happened because the reply delivery
plan only explicitly set the thread target when a NEW thread was created
(createdThreadId), but not when the message was in an existing thread.

The fix adds a fallback case: when threadChannel is set (we're in an
existing thread) but no new thread was created, explicitly route to
the thread's channel ID. This ensures all thread replies go to the
correct destination.
This commit is contained in:
Claw
2026-02-03 21:24:30 +00:00
committed by Shadow
parent 1af0edf7ff
commit e65b649993

View File

@@ -390,10 +390,18 @@ export function resolveDiscordReplyDeliveryPlan(params: {
const originalReplyTarget = params.replyTarget;
let deliverTarget = originalReplyTarget;
let replyTarget = originalReplyTarget;
// When a new thread was created, route to the new thread
if (params.createdThreadId) {
deliverTarget = `channel:${params.createdThreadId}`;
replyTarget = deliverTarget;
}
// When in an existing thread (not newly created), ensure we route to the thread
// This fixes #8278: autoThread replies sometimes going to root channel
else if (params.threadChannel?.id) {
deliverTarget = `channel:${params.threadChannel.id}`;
replyTarget = deliverTarget;
}
const allowReference = deliverTarget === originalReplyTarget;
const replyReference = createReplyReferencePlanner({
replyToMode: allowReference ? params.replyToMode : "off",