Asset

discord_http.asset module

class discord_http.asset.Asset(*, state, url, key, animated=False)

Bases: object

Represents a Discord asset (e.g. an image or video).

Parameters:
BASE: str = 'https://cdn.discordapp.com'
PROXY: str = 'https://media.discordapp.net'
url: str

The URL of the asset.

key: str

The key of the asset.

animated: bool

Whether the asset is animated.

async fetch(*, fallback=False) bytes

Fetches the asset.

Parameters:

fallback (bool) – Whether to fallback to a missing texture if the asset returns anything but HTTP 2XX. Defaults to False.

Return type:

bytes

Returns:

The asset data

async save(path, *, chunk_size=8192) int

Fetches the file from the attachment URL and saves it locally to the path.

Parameters:
  • path (str) – Path to save the file to, which includes the filename and extension. Example: ./path/to/file.png

  • chunk_size (int) – The amount of bytes to read at a time. Defaults to 8KB.

Return type:

int

Returns:

The amount of bytes written to the file

Raises:
replace(*, size=<MISSING>, format=<MISSING>) Self

Replace the asset with new values.

Parameters:
  • size (int) – The size of the asset

  • format (AssetFormatTypes) – The format of the asset

Return type:

Self

Returns:

The new asset object

with_static_format(format) Self

Replace the asset with a static format.

Parameters:

format (StaticFormatTypes) – The static format to use

Return type:

Self

Returns:

The new asset object, if animated, it will return no changes