Skip to content

Commit 0b3438b

Browse files
committed
add try catch for message issues
1 parent f8b42df commit 0b3438b

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

core/src/clients/discord/messages.ts

+27-22
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,39 @@ export async function sendMessageInChunks(
3939
inReplyTo: string,
4040
files: any[]
4141
): Promise<DiscordMessage[]> {
42+
4243
const sentMessages: DiscordMessage[] = [];
4344
const messages = splitMessage(content);
45+
try {
4446

45-
for (let i = 0; i < messages.length; i++) {
46-
const message = messages[i];
47-
if (
48-
message.trim().length > 0 ||
49-
(i === messages.length - 1 && files && files.length > 0)
50-
) {
51-
const options: any = {
52-
content: message.trim(),
53-
};
54-
55-
// if (i === 0 && inReplyTo) {
56-
// // Reply to the specified message for the first chunk
57-
// options.reply = {
58-
// messageReference: inReplyTo,
59-
// };
60-
// }
47+
for (let i = 0; i < messages.length; i++) {
48+
const message = messages[i];
49+
if (
50+
message.trim().length > 0 ||
51+
(i === messages.length - 1 && files && files.length > 0)
52+
) {
53+
const options: any = {
54+
content: message.trim(),
55+
};
56+
57+
// if (i === 0 && inReplyTo) {
58+
// // Reply to the specified message for the first chunk
59+
// options.reply = {
60+
// messageReference: inReplyTo,
61+
// };
62+
// }
63+
64+
if (i === messages.length - 1 && files && files.length > 0) {
65+
// Attach files to the last message chunk
66+
options.files = files;
67+
}
6168

62-
if (i === messages.length - 1 && files && files.length > 0) {
63-
// Attach files to the last message chunk
64-
options.files = files;
69+
const m = await channel.send(options);
70+
sentMessages.push(m);
6571
}
66-
67-
const m = await channel.send(options);
68-
sentMessages.push(m);
6972
}
73+
} catch (error) {
74+
prettyConsole.error("Error sending message:", error);
7075
}
7176

7277
return sentMessages;

0 commit comments

Comments
 (0)