Add some optional chaining to prevent issue with embeds

This commit is contained in:
whinis
2026-02-17 13:35:42 -05:00
committed by Rory&
parent 97d271b295
commit b2c9c8309e
+5 -6
View File
@@ -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);