Add some optional chaining to prevent issue with embeds
1 files changed, 5 insertions, 6 deletions
diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index 97040fd3..650a8b4b 100644
--- a/src/api/util/handlers/Message.ts
+++ b/src/api/util/handlers/Message.ts
@@ -502,14 +502,13 @@ export async function postHandleMessage(message: Message) {
continue;
}
}
-
- data.embeds.forEach((embed) => {
+ data.embeds?.forEach((embed) => {
if (!embed.type) {
embed.type = EmbedType.rich;
}
});
// Filter out embeds that could be links, start from scratch
- data.embeds = data.embeds.filter((embed) => embed.type === "rich");
+ data.embeds = data.embeds?.filter((embed) => embed.type === "rich");
const seenNormalizedUrls = new Set<string>();
const uniqueLinks: string[] = [];
@@ -534,7 +533,7 @@ export async function postHandleMessage(message: Message) {
if (uniqueLinks.length === 0) {
// No valid unique links found, update message to remove old embeds
- data.embeds = data.embeds.filter((embed) => embed.type === "rich");
+ data.embeds = data.embeds?.filter((embed) => embed.type === "rich");
const author = data.author?.toPublicUser();
const event = {
event: "MESSAGE_UPDATE",
@@ -567,7 +566,7 @@ export async function postHandleMessage(message: Message) {
});
if (cached) {
- data.embeds.push(cached.embed);
+ data.embeds?.push(cached.embed);
continue;
}
@@ -588,7 +587,7 @@ export async function postHandleMessage(message: Message) {
embed: embed,
});
cachePromises.push(cache.save());
- data.embeds.push(embed);
+ data.embeds?.push(embed);
}
} catch (e) {
console.error(`[Embeds] Error while generating embed for ${link}`, e);
|