Skip to content

Auto-proxy external URLs in activity assets#895

Open
FrederickStempfle wants to merge 1 commit into
dolfies:masterfrom
FrederickStempfle:feat/auto-proxy-activity-assets
Open

Auto-proxy external URLs in activity assets#895
FrederickStempfle wants to merge 1 commit into
dolfies:masterfrom
FrederickStempfle:feat/auto-proxy-activity-assets

Conversation

@FrederickStempfle
Copy link
Copy Markdown

Right now if you want to use an external image in your activity, you have to
manually call proxy_external_application_assets, get the proxied URLs back,
then pass those into ActivityAssets. This is pretty annoying.

This makes change_presence handle it for you — if your activity has an
application_id and the assets contain raw URLs that aren't from a known CDN
(discord, twitch, youtube, spotify), they get proxied automatically before
being sent to the gateway.

Closes #274

change_presence now automatically proxies raw external image URLs
in activity assets through Discord's media CDN. This means you can
pass any image URL directly to large_image/small_image on
ActivityAssets and it just works, as long as the activity has an
application_id set.

Closes dolfies#274
Copy link
Copy Markdown
Owner

@dolfies dolfies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the pr! i don't love the general concept of automatically making api requests, but this is what the client rpc server does i guess.

Comment thread discord/activity.py
or :meth:`~discord.Application.proxy_external_assets` to retrieved a proxied URL from Discord.
Otherwise, the image will not render in clients.
Arbitrary external image URLs (e.g. ``https://example.com/image.png``) can also
be passed directly to ``large_image`` or ``small_image``. When used with
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
be passed directly to ``large_image`` or ``small_image``. When used with
be passed directly to image parameters. When used with

excludes invite_cover_image but no point to list em anyway

Comment thread examples/rich_presence.py
)

# External URLs are automatically proxied through Discord's CDN
# when passed directly to large_image/small_image.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# when passed directly to large_image/small_image.

redundant

Comment thread examples/rich_presence.py
import discord

# Your Developer Portal Application ID (used for proxying external assets)
# Your Developer Portal Application ID
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Your Developer Portal Application ID
# Your Developer Portal Application ID (used for proxying external assets)

this comment is still useful

Comment thread discord/client.py
ValueError
More than one custom activity was passed.
"""
if activity is not MISSING and activities is not MISSING:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of overcomplicating this method and polluting Client, add a _to_processed_dict() method to the Activity object that does what _proxy_activity_assets() is doing and returns the dict (make sure to not forget to stub it on BaseActivity!)

@dolfies
Copy link
Copy Markdown
Owner

dolfies commented Feb 28, 2026

oh i also forgot, this needs a versionchanged: directive

@mikasa
Copy link
Copy Markdown

mikasa commented Mar 4, 2026

i lowkey kinda support this.. but then at the same time, yeah.. you don't wanna be making automatic requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't set activity image, am I doing something wrong?

3 participants