@@ -70,6 +70,8 @@ type DiscordSendOpts = {
7070 allowedMentions ?: DiscordAllowedMentions ;
7171 /** Persist each concrete platform send before any later chunk can fail. */
7272 onDeliveryResult ?: ( result : DiscordSendResult ) => Promise < void > | void ;
73+ /** @internal Refresh durable custody immediately before Discord REST I/O. */
74+ onPlatformSendDispatch ?: ( ) => Promise < void > ;
7375} ;
7476
7577type DiscordClientRequest = ReturnType < typeof createDiscordClient > [ "request" ] ;
@@ -92,6 +94,7 @@ async function sendDiscordThreadTextChunks(params: {
9294 suppressEmbeds ?: boolean ;
9395 allowedMentions ?: DiscordAllowedMentions ;
9496 onResult ?: DiscordSendProgress ;
97+ onPlatformSendDispatch ?: ( ) => Promise < void > ;
9598} ) : Promise < void > {
9699 for ( const chunk of params . chunks ) {
97100 await sendDiscordText ( {
@@ -106,6 +109,7 @@ async function sendDiscordThreadTextChunks(params: {
106109 allowedMentions : params . allowedMentions ,
107110 maxChars : params . maxChars ,
108111 onResult : params . onResult ,
112+ onPlatformSendDispatch : params . onPlatformSendDispatch ,
109113 } ) ;
110114 }
111115}
@@ -238,6 +242,7 @@ export async function sendMessageDiscord(
238242 } ) ;
239243 let threadRes : { id : string ; message ?: { id : string ; channel_id : string } } ;
240244 try {
245+ await opts . onPlatformSendDispatch ?.( ) ;
241246 threadRes = ( await request (
242247 ( ) =>
243248 createThread < { id : string ; message ?: { id : string ; channel_id : string } } > (
@@ -309,6 +314,7 @@ export async function sendMessageDiscord(
309314 allowedMentions : opts . allowedMentions ,
310315 maxChars : textLimit ,
311316 onResult : reportThreadResult ,
317+ onPlatformSendDispatch : opts . onPlatformSendDispatch ,
312318 } ) ;
313319 await sendDiscordThreadTextChunks ( {
314320 rest,
@@ -322,6 +328,7 @@ export async function sendMessageDiscord(
322328 suppressEmbeds,
323329 allowedMentions : opts . allowedMentions ,
324330 onResult : reportThreadResult ,
331+ onPlatformSendDispatch : opts . onPlatformSendDispatch ,
325332 } ) ;
326333 } else {
327334 await sendDiscordThreadTextChunks ( {
@@ -336,6 +343,7 @@ export async function sendMessageDiscord(
336343 suppressEmbeds,
337344 allowedMentions : opts . allowedMentions ,
338345 onResult : reportThreadResult ,
346+ onPlatformSendDispatch : opts . onPlatformSendDispatch ,
339347 } ) ;
340348 }
341349 } catch ( err ) {
@@ -391,6 +399,7 @@ export async function sendMessageDiscord(
391399 allowedMentions : opts . allowedMentions ,
392400 maxChars : textLimit ,
393401 onResult : reportResult ,
402+ onPlatformSendDispatch : opts . onPlatformSendDispatch ,
394403 } ) ;
395404 } else {
396405 result = await sendDiscordText ( {
@@ -408,6 +417,7 @@ export async function sendMessageDiscord(
408417 allowedMentions : opts . allowedMentions ,
409418 maxChars : textLimit ,
410419 onResult : reportResult ,
420+ onPlatformSendDispatch : opts . onPlatformSendDispatch ,
411421 } ) ;
412422 }
413423 } catch ( err ) {
@@ -447,6 +457,7 @@ export async function sendStickerDiscord(
447457 enforce_nonce : true ,
448458 ...( flags ? { flags } : { } ) ,
449459 } ;
460+ await opts . onPlatformSendDispatch ?.( ) ;
450461 const res = ( await request (
451462 ( ) => createChannelMessage < { id : string ; channel_id : string } > ( rest , channelId , { body } ) ,
452463 "sticker" ,
@@ -474,6 +485,7 @@ export async function sendPollDiscord(
474485 enforce_nonce : true ,
475486 ...( flags ? { flags } : { } ) ,
476487 } ;
488+ await opts . onPlatformSendDispatch ?.( ) ;
477489 const res = ( await request (
478490 ( ) => createChannelMessage < { id : string ; channel_id : string } > ( rest , channelId , { body } ) ,
479491 "poll" ,
0 commit comments