@@ -208,6 +208,17 @@ export async function sendMessageDiscord(
208208
209209 // Forum/Media channels reject POST /messages; auto-create a thread post instead.
210210 const channel = await resolveDiscordChannel ( rest , channelId ) ;
211+ const deliveredResults : DiscordSendResult [ ] = [ ] ;
212+ let deliveryThreadId : string | undefined ;
213+ const reportResult : DiscordSendProgress = async ( progressResult , kind , replyToId ) => {
214+ const deliveredResult = toDiscordSendResult ( progressResult , deliveryThreadId ?? channelId , {
215+ kind,
216+ threadId : deliveryThreadId ,
217+ reply : createReusableDiscordReplyReference ( replyToId ) ,
218+ } ) ;
219+ deliveredResults . push ( deliveredResult ) ;
220+ await opts . onDeliveryResult ?.( deliveredResult ) ;
221+ } ;
211222
212223 if ( isForumLikeChannel ( channel ) ) {
213224 if ( ( ( channel . flags ?? 0 ) & DISCORD_FORUM_REQUIRE_TAG_FLAG ) !== 0 ) {
@@ -275,6 +286,7 @@ export async function sendMessageDiscord(
275286 }
276287
277288 const threadId = threadRes . id ;
289+ deliveryThreadId = threadId ;
278290 const messageId = threadRes . message ?. id ?? threadId ;
279291 const resultChannelId = threadRes . message ?. channel_id ?? threadId ;
280292 const remainingChunks = chunks . slice ( 1 ) ;
@@ -286,13 +298,8 @@ export async function sendMessageDiscord(
286298 channelId ,
287299 { kind : "text" , threadId } ,
288300 ) ;
289- const deliveredResults : DiscordSendResult [ ] = [ starterResult ] ;
301+ deliveredResults . push ( starterResult ) ;
290302 await opts . onDeliveryResult ?.( starterResult ) ;
291- const reportThreadResult : DiscordSendProgress = async ( result , kind ) => {
292- const deliveredResult = toDiscordSendResult ( result , threadId , { kind, threadId } ) ;
293- deliveredResults . push ( deliveredResult ) ;
294- await opts . onDeliveryResult ?.( deliveredResult ) ;
295- } ;
296303
297304 try {
298305 if ( opts . mediaUrl ) {
@@ -314,7 +321,7 @@ export async function sendMessageDiscord(
314321 suppressEmbeds,
315322 allowedMentions : opts . allowedMentions ,
316323 maxChars : textLimit ,
317- onResult : reportThreadResult ,
324+ onResult : reportResult ,
318325 onPlatformSendDispatch : opts . onPlatformSendDispatch ,
319326 } ) ;
320327 await sendDiscordThreadTextChunks ( {
@@ -328,7 +335,7 @@ export async function sendMessageDiscord(
328335 silent : opts . silent ,
329336 suppressEmbeds,
330337 allowedMentions : opts . allowedMentions ,
331- onResult : reportThreadResult ,
338+ onResult : reportResult ,
332339 onPlatformSendDispatch : opts . onPlatformSendDispatch ,
333340 } ) ;
334341 } else {
@@ -343,7 +350,7 @@ export async function sendMessageDiscord(
343350 silent : opts . silent ,
344351 suppressEmbeds,
345352 allowedMentions : opts . allowedMentions ,
346- onResult : reportThreadResult ,
353+ onResult : reportResult ,
347354 onPlatformSendDispatch : opts . onPlatformSendDispatch ,
348355 } ) ;
349356 }
@@ -369,14 +376,6 @@ export async function sendMessageDiscord(
369376 }
370377
371378 let result : DiscordChannelMessageResult ;
372- const reportResult : DiscordSendProgress = async ( progressResult , kind , replyToId ) => {
373- await opts . onDeliveryResult ?.(
374- toDiscordSendResult ( progressResult , channelId , {
375- kind,
376- reply : createReusableDiscordReplyReference ( replyToId ) ,
377- } ) ,
378- ) ;
379- } ;
380379 try {
381380 if ( opts . mediaUrl ) {
382381 result = await sendDiscordMedia ( {
@@ -436,10 +435,11 @@ export async function sendMessageDiscord(
436435 accountId : accountInfo . accountId ,
437436 direction : "outbound" ,
438437 } ) ;
439- return toDiscordSendResult ( result , channelId , {
440- kind : opts . mediaUrl ? "media" : opts . components || opts . embeds ? "card" : "text" ,
441- reply : opts . reply ,
442- } ) ;
438+ return {
439+ messageId : result . id || "unknown" ,
440+ channelId : result . channel_id ?? channelId ,
441+ receipt : createDiscordSendReceiptFromResults ( { results : deliveredResults } ) ,
442+ } ;
443443}
444444
445445export async function sendStickerDiscord (
0 commit comments