platforms.embed_media_resolver module
Resolve Discord embed images and stickers into first-class attachments.
Embed images (link previews, other bots’ rich embeds, crossposts) and
stickers historically reached the pipeline as text only — a serialized
<image>URL</image> line or [Sticker: name] label — so whether the
model ever saw the pixels depended on a downstream URL regex that cannot
match extension-less og:image links and never fires for stickers. This
module downloads those assets at the gateway, exactly like attachments,
so the bytes travel in the inbound envelope.
Mirrors platforms.emoji_resolver: candidate extraction is pure and
separately testable; downloads go through the media cache when available.
- platforms.embed_media_resolver.embed_image_candidates(message)
(download_url, origin_url)pairs for a message’s embed images.Prefers each embed’s full
imageover itsthumbnail(an embed can carry both for the same asset) and the Discord media-proxy URL over the origin (the proxy is cached, CORS-friendly, and carries a fresh signature for re-embedded CDN attachments). The gateway is the single owner of every embed image — including ones whose URL is pasted verbatim in the message text — because serialize_embed tags them as<image>URL</image>and the inference-side extractor skips tagged URLs; skipping here too would mean NOBODY fetches the image. Deduplicates across embeds, including forwarded-snapshot embeds.
- platforms.embed_media_resolver.sticker_candidates(message)
(url, mimetype, filename)for a message’s raster stickers.Includes forwarded-snapshot stickers; skips lottie (vector JSON).
- async platforms.embed_media_resolver.collect_embed_images(message, *, max_images=4, media_cache=None, session=None)
Download up to
max_imagesembed images as attachments.session is an optional shared
aiohttp.ClientSessionto fetch through; it is only forwarded when non-Noneso that callers (and tests) which stub_download_imagewith the historical signature keep working unchanged.
- async platforms.embed_media_resolver.collect_sticker_images(message, *, max_stickers=3, media_cache=None, session=None)
Download up to
max_stickersraster stickers as attachments.session is forwarded only when non-
None— seecollect_embed_images().