From 1210b2acaa7210127a2f4a47ba66369483a601e9 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Mon, 2 Nov 2020 17:25:56 +0200 Subject: [PATCH] Fix postSystemMessage() text not being chunked This would cause errors if the system message was over 2000 characters in length. --- src/data/Thread.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/data/Thread.js b/src/data/Thread.js index 863937d..45f1585 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -89,10 +89,11 @@ class Thread { try { let firstMessage; - if (typeof content === "string") { - // Content is a string, chunk it and send it as individual messages. + const textContent = typeof content === "string" ? content : content.content; + if (textContent) { + // Text content is included, chunk it and send it as individual messages. // Files (attachments) are only sent with the last message. - const chunks = utils.chunkMessageLines(content); + const chunks = utils.chunkMessageLines(textContent); for (const [i, chunk] of chunks.entries()) { // Only send embeds, files, etc. with the last message const msg = (i === chunks.length - 1) @@ -102,7 +103,7 @@ class Thread { firstMessage = firstMessage || msg; } } else { - // Content is a full message content object, send it as-is with the files (if any) + // No text content, send as one message firstMessage = await bot.createMessage(this.channel_id, content, file); }