Activity

Represents a Discord activity.

Attributes

Metadata of the activity containing extra fields about itself.

The activity's type.

Properties

application_id

assets

color

Returns the activity's color.

Returns

color : Color

created_at

details

discord_side_id

Returns the activity's Discord side id. If the activity implements id returns that, else tries to look it put from constants.

Returns

discord_side_id : str

emoji

end

Returns when the activity ended or will end if applicable.

Returns

start : None, datetime

flags

id

image_large_url

Returns the activity's large asset image's url. If the activity has no large asset image, then returns None.

This function is a shared property of Activity-s.

Returns

url : None, str

image_small_url

Returns the activity's small asset image's url. If the activity has no small asset image, then returns None.

This function is a shared property of Activity-s.

Returns

url : None, str

name

party

secrets

session_id

spotify_album_cover_url

Returns the spotify activity's currently playing track's album's cover url if applicable.

Only applicable for spotify activities.

Returns

album_cover_url : None, str

spotify_cover_id

If the user listens to spotify, returns it's spotify name.

Only applicable for spotify activities.

Returns

name : None, str

spotify_track_duration

Returns the spotify activity's duration, or None if not applicable.

Only applicable for spotify activities.

Returns

duration : None, timedelta

spotify_track_id

Returns the song's identifier.

Only applicable for spotify activities.

Returns

track_id : None, str

spotify_track_url

Returns url to the spotify activity's song.

Only applicable for spotify activities.

Returns

url : None, str

start

Returns when the activity was started if applicable.

Returns

start : None, datetime

state

sync_id

timestamps

twitch_name

If the user streams on twitch, returns it's twitch name.

Only applicable for stream activities.

Returns

name : None, str

twitch_preview_image_url

Returns the activity's twitch preview image url.

Only applicable for stream activities.

Returns

preview_image_url : None, str

url

youtube_preview_image_url

Returns the activity's youtube preview image url.

Only applicable for stream activities.

Returns

preview_image_url : None, str

youtube_video_id

If the user streams on youtube, returns it's stream's respective video identifier.

Only applicable for stream activities.

Returns

video_id : None, str

Methods

__new__(...)

Creates a new activity with the given parameters.

ParameterTypeOptionalKeyword onlyDefaultDescription
name

None, str

None

The name of the activity.

activity_type

int, ActivityType

The type value of the activity.

**keyword_parameters

Keyword parameters

Additional parameters to pass to the activity-type specific constructor.

activity_id

int

The id of the activity.

application_id

int

The id of the activity's application.

assets

None, ActivityAssets

The activity's assets.

created_at

None, datetime

When the activity was created.

details

None, str

What the player is currently doing.

flags

ActivityFlag, int

The flags of the activity.

party

None, ActivityParty

The activity's party.

secrets

None, ActivitySecrets

The activity's secrets.

session_id

None, str

Spotify activity's session's id.

state

None, str

The player's current party status.

sync_id

None, str

The ID of the currently playing track of a spotify activity.

timestamps

ActivityTimestamps

The activity's timestamps.

url

None, str

The url of the activity. Only twitch and youtube urls are supported.

Raises

TypeError

  • If a parameter's type is incorrect.
  • If extra or unused parameters were given.

ValueError

  • If a parameter's value is incorrect.

copy()

Copies the activity.

Returns

new : instance<type<self>>

copy_with(...)

Copies the activity with the given fields.

ParameterTypeOptionalKeyword onlyDescription
activity_type

int, ActivityType

The type value of the activity.

**keyword_parameters

Keyword parameters

Additional parameters to pass to the activity-type specific constructor.

activity_id

int

The id of the activity.

application_id

int

The id of the activity's application.

assets

None, ActivityAssets

The activity's assets.

created_at

None, datetime

When the activity was created.

details

None, str

What the player is currently doing.

flags

ActivityFlag, int

The flags of the activity.

name

None, str

The name of the activity.

party

None, ActivityParty

The activity's party.

secrets

None, ActivitySecrets

The activity's secrets.

session_id

None, str

Spotify activity's session's id.

state

None, str

The player's current party status.

sync_id

None, str

The ID of the currently playing track of a spotify activity.

timestamps

ActivityTimestamps

The activity's timestamps.

url

None, str

The url of the activity. Only twitch and youtube urls are supported.

Returns

new : instance<type<self>>

Raises

TypeError

  • If a parameter's type is incorrect.
  • If extra or unused parameters were given.

ValueError

  • If a parameter's value is incorrect.

from_data(data)

Creates an activity from the json data sent by Discord.

If the data is None returns ACTIVITY_UNKNOWN.

ParameterTypeDescription
data

None, dict of (str, object) items

Activity data received from Discord.

Returns

activity : Activity

image_large_url_as(...)

Returns the activity's large asset image's url. If the activity has no large asset image, then returns None.

This function is a shared method of Activity-s.

ParameterTypeOptionalDefaultDescription
ext

None, str

None

The extension of the image's url. Can be any of: 'jpg', 'jpeg', 'png', 'webp'.

size

None, int

None

The preferred minimal size of the image's url.

Returns

url : None, str

Raises

ValueError

If ext, size was not passed as any of the expected values.

image_small_url_as(...)

Returns the activity's small asset image's url. If the activity has no small asset image, then returns None.

This function is a shared method of Activity-s.

ParameterTypeOptionalDefaultDescription
ext

None, str

None

The extension of the image's url. Can be any of: 'jpg', 'jpeg', 'png', 'webp'.

size

None, int

None

The preferred minimal size of the image's url.

Returns

url : None, str

Raises

ValueError

If ext, size was not passed as any of the expected values.

to_data(...)

Converts the activity to json serializable dictionary, which can be sent with bot account to change activity.

ParameterTypeOptionalKeyword onlyDefaultDescription
defaults

bool

False

Whether fields with the default values should be included as well.

include_internals

bool

False

Whether internal fields, like id-s should be present as well.

user

bool

False

Whether not only bot compatible fields should be included.

Returns

data : dict of (str, object) items

_difference_update_attributes(data)

Updates the activity and returns the changes in a dict of (attribute-name, old-value) items.

ParameterTypeDescription
data

dict of (str, object) items

Data received from Discord.

Returns

old_attributes : dict of (str, object) items

All item in the returned dict is optional.

Returned Data Structure

KeysValues
assetsNone, ActivityAssets
created_atNone, datetime
detailsNone, str
emojiNone, Emoji
flagsActivityFlag
namestr
metadataActivityMetadataBase
partyNone, ActivityParty
secretsNone, ActivitySecrets
session_idNone, str
stateNone, str
sync_idNone, str
timestampsNone, ActivityTimestamps
typeActivityType
urlNone, str

_update_attributes(data)

Updates the activity by overwriting it's old attributes.

ParameterTypeDescription
data

dict of (str, object) items

Data received from Discord.

__eq__()

Returns whether the two activities are equal.

__getattr__()

Drops a rich attribute error.

__hash__()

Returns the activity's hash value.

__repr__()

Returns the activity's representation.