Asset

discord_http.asset module

class discord_http.asset.Asset(*, state: DiscordAPI, url: str, key: str, animated: bool = False)[source]

Bases: object

BASE = 'https://cdn.discordapp.com'
PROXY = 'https://media.discordapp.net'
async fetch() bytes[source]

Fetches the asset

Returns:

The asset data

Return type:

bytes

is_animated() bool[source]

Whether the asset is animated or not

Returns:

Whether the asset is animated or not

Return type:

bool

property key: str

The key of the asset

Returns:

The key of the asset

Return type:

str

replace(*, size: int = <MISSING>, format: ~typing.Literal['webp', 'jpeg', 'jpg', 'png', 'gif'] = <MISSING>) Self[source]

Replace the asset with new values

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

  • format (AssetFormatTypes) – The format of the asset

Returns:

The new asset object

Return type:

Self

async save(path: str) int[source]

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

Returns:

The amount of bytes written to the file

Return type:

int

property url: str

The URL of the asset

Returns:

The URL of the asset

Return type:

str

with_static_format(format: Literal['webp', 'jpeg', 'jpg', 'png']) Self[source]

Replace the asset with a static format

Parameters:

format (StaticFormatTypes) – The static format to use

Returns:

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

Return type:

Self