Skip to content

Commit

Permalink
add try catch for message issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Nov 4, 2024
1 parent f8b42df commit 0b3438b
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions core/src/clients/discord/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,39 @@ export async function sendMessageInChunks(
inReplyTo: string,
files: any[]
): Promise<DiscordMessage[]> {

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;
Expand Down

0 comments on commit 0b3438b

Please sign in to comment.