From 013c8d8e7aec0c7d0cf8363d8d7be5e3abb97297 Mon Sep 17 00:00:00 2001 From: Pablo Stebler Date: Tue, 24 Feb 2026 00:01:52 +0100 Subject: [PATCH] Add support for attachment:// urls Closes #1551. --- src/api/util/handlers/Message.ts | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index 85fb81f8d..0c58ff837 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -474,6 +474,53 @@ export async function handleMessage(opts: MessageOptions): Promise { } } + const attachmentIndices = new Map( + message.attachments?.map((attachment, index) => { + return [`attachment://${attachment.filename}`, index]; + }), + ); + const attachmentsToRemove = new Set(); + function fetchAttachment(url: string | undefined): Attachment | undefined { + if (url == undefined) { + return undefined; + } + const index = attachmentIndices.get(url); + if (index === undefined) { + return undefined; + } + const attachment = message.attachments?.[index]; + if (attachment === undefined) { + return undefined; + } + attachmentsToRemove.add(index); + return attachment; + } + for (const embed of message.embeds) { + const footer = embed.footer; + const footerAttachment = fetchAttachment(footer?.icon_url); + if (footerAttachment !== undefined) { + footer!.icon_url = footerAttachment.url; + footer!.proxy_icon_url = footerAttachment.proxy_url; + } + + const image = embed.image; + const imageAttachment = fetchAttachment(image?.url); + if (imageAttachment !== undefined) { + image!.url = imageAttachment.url; + image!.proxy_url = imageAttachment.proxy_url; + } + + const author = embed.author; + const authorAttachment = fetchAttachment(author?.icon_url); + if (authorAttachment !== undefined) { + author!.icon_url = authorAttachment.url; + author!.proxy_icon_url = authorAttachment.proxy_url; + } + } + message.attachments = message.attachments?.filter((_, index) => { + return !attachmentsToRemove.has(index); + }); + // TODO: check and put it all in the body return message;