summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorwhinis <whinis@whinis.com>2026-02-17 13:35:42 -0500
committerRory& <root@rory.gay>2026-02-18 14:19:15 +0100
commitb2c9c8309ecf43d87a1029166fd4bebd83683944 (patch)
treefb97bcc0c31bd2a8ecff9a5ada6990b5689bf790 /src/api
parentRenamed to JsonNumber and removed from incorrectly typed date field (diff)
downloadserver-ts-b2c9c8309ecf43d87a1029166fd4bebd83683944.tar.xz
Add some optional chaining to prevent issue with embeds
Diffstat (limited to 'src/api')
-rw-r--r--src/api/util/handlers/Message.ts11
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);