From 0b3438b6a42745d422e755fa3030b516218717a0 Mon Sep 17 00:00:00 2001 From: moon Date: Sun, 3 Nov 2024 21:02:54 -0800 Subject: [PATCH] add try catch for message issues --- core/src/clients/discord/messages.ts | 49 +++++++++++++++------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/core/src/clients/discord/messages.ts b/core/src/clients/discord/messages.ts index 35559e91..650cc883 100644 --- a/core/src/clients/discord/messages.ts +++ b/core/src/clients/discord/messages.ts @@ -39,34 +39,39 @@ export async function sendMessageInChunks( inReplyTo: string, files: any[] ): Promise { + const sentMessages: DiscordMessage[] = []; const messages = splitMessage(content); + try { - for (let i = 0; i < messages.length; i++) { - const message = messages[i]; - if ( - message.trim().length > 0 || - (i === messages.length - 1 && files && files.length > 0) - ) { - const options: any = { - content: message.trim(), - }; - - // if (i === 0 && inReplyTo) { - // // Reply to the specified message for the first chunk - // options.reply = { - // messageReference: inReplyTo, - // }; - // } + for (let i = 0; i < messages.length; i++) { + const message = messages[i]; + if ( + message.trim().length > 0 || + (i === messages.length - 1 && files && files.length > 0) + ) { + const options: any = { + content: message.trim(), + }; + + // if (i === 0 && inReplyTo) { + // // Reply to the specified message for the first chunk + // options.reply = { + // messageReference: inReplyTo, + // }; + // } + + if (i === messages.length - 1 && files && files.length > 0) { + // Attach files to the last message chunk + options.files = files; + } - if (i === messages.length - 1 && files && files.length > 0) { - // Attach files to the last message chunk - options.files = files; + const m = await channel.send(options); + sentMessages.push(m); } - - const m = await channel.send(options); - sentMessages.push(m); } + } catch (error) { + prettyConsole.error("Error sending message:", error); } return sentMessages;