Activity
extends Part
in package
implements
Stringable
The Activity part describes activities the member is undertaking.
If a user's Profile Privacy Setting is set to Friends Only, or to Friends & Small Servers Only in a guild with more than 200 members,
their custom status (an Activity object with type 4) is omitted from the activities field of Presence Update events dispatched to that guild.
This applies to apps and bots subscribed to the guild's presence.
Other activity types (Playing, Streaming, Listening, Watching, Competing) are not affected by this setting but may be controlled by Activity Sharing settings.
Tags
Table of Contents
Interfaces
- Stringable
Constants
- FLAG_EMBEDDED : mixed = 1 << 8
- FLAG_INSTANCE : mixed = 1 << 0
- FLAG_JOIN : mixed = 1 << 1
- FLAG_JOIN_REQUEST : mixed = 1 << 3
- FLAG_PARTY_PRIVACY_FRIENDS : mixed = 1 << 6
- FLAG_PARTY_PRIVACY_VOICE_CHANNEL : mixed = 1 << 7
- FLAG_PLAY : mixed = 1 << 5
- FLAG_SPECTATE : mixed = 1 << 2
- FLAG_SYNC : mixed = 1 << 4
- STATUS_DISPLAY_TYPE_DETAILS : mixed = 2
- "Listening to Never Gonna Give You Up"
- STATUS_DISPLAY_TYPE_NAME : mixed = 0
- "Listening to Spotify"
- STATUS_DISPLAY_TYPE_STATE : mixed = 1
- "Listening to Rick Astley"
- STATUS_DND : mixed = 'dnd'
- Do Not Disturb.
- STATUS_IDLE : mixed = 'idle'
- AFK.
- STATUS_INVISIBLE : mixed = 'invisible'
- Invisible and shown as offline.
- STATUS_OFFLINE : mixed = 'offline'
- Offline.
- STATUS_ONLINE : mixed = 'online'
- Online.
- TYPE_COMPETING : mixed = 5
- Competing in {name}
- TYPE_CUSTOM : mixed = 4
- {emoji} {name}
- TYPE_GAME : mixed = self::TYPE_PLAYING
- TYPE_LISTENING : mixed = 2
- Listening to {name}
- TYPE_PLAYING : mixed = 0
- Playing {name}
- TYPE_STREAMING : mixed = 1
- Streaming {details}
- TYPE_WATCHING : mixed = 3
- Watching {name}
Properties
- $application_id : ?string|null
- $assets : ?Assets|null
- $buttons : ?ExCollectionInterface<string|int, Button>|array<string|int, Button>|null
- $created : bool
- Is the part already created in the Discord servers?
- $created_at : Carbon|null
- $details : ?string|null
- $details_url : ?string|null
- $emoji : ?Emoji|null
- $flags : ?int|null
- $instance : ?bool|null
- $name : string
- $party : ?Party|null
- $scriptData : mixed
- Custom script data.
- $secrets : ?Secrets|null
- $state : ?string|null
- $state_url : ?string|null
- $status_display_type : ?int|null
- $timestamps : ?Timestamps|null
- $type : int
- $url : ?string|null
- $attributes : array<string|int, mixed>
- The parts attributes.
- $discord : Discord
- The Discord client.
- $factory : Factory
- The factory.
- $fillable : array<string|int, mixed>
- The parts fillable attributes.
- $hidden : array<string|int, mixed>
- Attributes that are hidden from debug info.
- $http : Http
- The HTTP client.
- $repositories : array<string|int, mixed>
- An array of repositories that can exist in a part.
- $repositories_cache : array<string|int, mixed>
- An array of repositories.
- $visible : array<string|int, mixed>
- Attributes which are visible from debug info.
Methods
- __construct() : mixed
- Create a new part instance.
- __debugInfo() : array<string|int, mixed>
- Debug representation for `var_dump()`.
- __get() : mixed
- Handles dynamic get calls onto the part.
- __isset() : bool
- Handles isset() and empty() on the part's magic properties.
- __serialize() : array<string|int, mixed>
- The raw attributes, for PHP native serialization.
- __set() : void
- Handles dynamic set calls onto the part.
- __toString() : string
- Converts the activity to a string.
- __unserialize() : void
- Restores attributes from PHP native unserialization.
- fetch() : PromiseInterface<string|int, static>
- Fetches any missing information about the part from Discord's servers.
- fill() : void
- Fills the parts attributes from an array.
- getConstants() : array<string|int, mixed>
- Returns an array of constant names and their values.
- getCreatableAttributes() : array<string|int, mixed>
- Returns the attributes needed to create.
- getDiscord() : Discord
- Get the Discord instance that owns this Part.
- getPublicAttributes() : array<string|int, mixed>
- Returns an array of public attributes.
- getRawAttributes() : array<string|int, mixed>
- Returns an array of raw attributes.
- getRepository() : AbstractRepository|null
- Gets the originating repository of the part.
- getRepositoryAttributes() : array<string|int, mixed>
- Gets the attributes to pass to repositories.
- getUpdatableAttributes() : array<string|int, mixed>
- Returns the updatable attributes.
- isPartial() : bool
- Whether the part is considered partial i.e. missing information which can be fetched from Discord.
- jsonSerialize() : array<string|int, mixed>
- Provides data when the part is encoded into JSON. Used for JsonSerializable.
- offsetExists() : bool
- Checks if an attribute exists via key. Used for ArrayAccess.
- offsetGet() : mixed
- Gets an attribute via key. Used for ArrayAccess.
- offsetSet() : void
- Sets an attribute via key. Used for ArrayAccess.
- offsetUnset() : void
- Unsets an attribute via key. Used for ArrayAccess.
- save() : PromiseInterface<string|int, Part>
- Save the part with its originating repository.
- serialize() : ?string
- Serializes the data. Used for Serializable.
- unserialize() : void
- Unserializes some data and stores it. Used for Serializable.
- afterConstruct() : void
- Called after the part has been constructed.
- attributeCarbonHelper() : Carbon|null
- Helps with getting ISO8601 timestamp attributes.
- attributeCollectionHelper() : ExCollectionInterface
- Helps with getting Part attributes.
- attributePartHelper() : Part|null
- Helps with getting Part attributes.
- attributeTypedCollectionHelper() : ExCollectionInterface
- Helps with getting Part attributes for classes with extended types.
- checkForGetMutator() : string|false
- Checks if there is a get mutator present.
- checkForSetMutator() : string|false
- Checks if there is a set mutator present.
- getAssetsAttribute() : Assets|null
- Gets the assets object of the activity.
- getAttribute() : mixed
- Gets an attribute on the part.
- getButtonsAttribute() : ExCollectionInterface<string|int, Button>|array<string|int, Button>|null
- Gets the buttons array of the activity.
- getCreatedAtAttribute() : Carbon|null
- Gets the created at timestamp.
- getEmojiAttribute() : Emoji|null
- Gets the emoji object of the activity.
- getPartyAttribute() : Party|null
- Gets the party object of the activity.
- getSecretsAttribute() : Secrets|null
- Gets the secrets object of the activity.
- getTimestampsAttribute() : Timestamps|null
- Gets the timestamps object of the activity.
- makeOptionalAttributes() : array<string|int, mixed>
- Return key-value attributes if it has been filled.
- setAttribute() : void
- Sets an attribute on the part.
- studly() : string
- Converts a string to studlyCase.
Constants
FLAG_EMBEDDED
public
mixed
FLAG_EMBEDDED
= 1 << 8
FLAG_INSTANCE
public
mixed
FLAG_INSTANCE
= 1 << 0
FLAG_JOIN
public
mixed
FLAG_JOIN
= 1 << 1
FLAG_JOIN_REQUEST
public
mixed
FLAG_JOIN_REQUEST
= 1 << 3
FLAG_PARTY_PRIVACY_FRIENDS
public
mixed
FLAG_PARTY_PRIVACY_FRIENDS
= 1 << 6
FLAG_PARTY_PRIVACY_VOICE_CHANNEL
public
mixed
FLAG_PARTY_PRIVACY_VOICE_CHANNEL
= 1 << 7
FLAG_PLAY
public
mixed
FLAG_PLAY
= 1 << 5
FLAG_SPECTATE
public
mixed
FLAG_SPECTATE
= 1 << 2
FLAG_SYNC
public
mixed
FLAG_SYNC
= 1 << 4
STATUS_DISPLAY_TYPE_DETAILS
"Listening to Never Gonna Give You Up"
public
mixed
STATUS_DISPLAY_TYPE_DETAILS
= 2
STATUS_DISPLAY_TYPE_NAME
"Listening to Spotify"
public
mixed
STATUS_DISPLAY_TYPE_NAME
= 0
STATUS_DISPLAY_TYPE_STATE
"Listening to Rick Astley"
public
mixed
STATUS_DISPLAY_TYPE_STATE
= 1
STATUS_DND
Do Not Disturb.
public
mixed
STATUS_DND
= 'dnd'
STATUS_IDLE
AFK.
public
mixed
STATUS_IDLE
= 'idle'
STATUS_INVISIBLE
Invisible and shown as offline.
public
mixed
STATUS_INVISIBLE
= 'invisible'
STATUS_OFFLINE
Offline.
public
mixed
STATUS_OFFLINE
= 'offline'
STATUS_ONLINE
Online.
public
mixed
STATUS_ONLINE
= 'online'
TYPE_COMPETING
Competing in {name}
public
mixed
TYPE_COMPETING
= 5
TYPE_CUSTOM
{emoji} {name}
public
mixed
TYPE_CUSTOM
= 4
TYPE_GAME
Use Activity::TYPE_PLAYING
public
mixed
TYPE_GAME
= self::TYPE_PLAYING
TYPE_LISTENING
Listening to {name}
public
mixed
TYPE_LISTENING
= 2
TYPE_PLAYING
Playing {name}
public
mixed
TYPE_PLAYING
= 0
TYPE_STREAMING
Streaming {details}
public
mixed
TYPE_STREAMING
= 1
TYPE_WATCHING
Watching {name}
public
mixed
TYPE_WATCHING
= 3
Properties
$application_id
public
?string|null
$application_id
Application id for the game.
$assets
public
?Assets|null
$assets
Images for the presence and their hover texts.
$buttons
public
?ExCollectionInterface<string|int, Button>|array<string|int, Button>|null
$buttons
The custom buttons shown in the Rich Presence (max 2).
$created
Is the part already created in the Discord servers?
public
bool
$created
= false
Whether the part has been created.
$created_at
public
Carbon|null
$created_at
Timestamp of when the activity was added to the user's session.
$details
public
?string|null
$details
What the player is currently doing.
$details_url
public
?string|null
$details_url
URL that is linked when clicking on the details text
$emoji
public
?Emoji|null
$emoji
The emoji used for a custom status.
$flags
public
?int|null
$flags
Activity flags ORd together, describes what the payload includes.
$instance
public
?bool|null
$instance
Whether or not the activity is an instanced game session.
$name
public
string
$name
The activity's name.
$party
public
?Party|null
$party
Information for the current party of the player.
$scriptData
Custom script data.
Relying on this variable with dynamic caching is discouraged.
public
mixed
$scriptData
Used for storing custom information, used by end products.
$secrets
public
?Secrets|null
$secrets
Secrets for Rich Presence joining and spectating.
$state
public
?string|null
$state
The user's current party status, or text used for a custom status.
$state_url
public
?string|null
$state_url
URL that is linked when clicking on the state text.
$status_display_type
public
?int|null
$status_display_type
Status display type; controls which field is displayed in the user's status text in the member list.
$timestamps
public
?Timestamps|null
$timestamps
Unix timestamps for start and/or end of the game.
$type
public
int
$type
Activity type.
$url
public
?string|null
$url
Stream url, is validated when type is 1.
$attributes
The parts attributes.
protected
array<string|int, mixed>
$attributes
= []
The parts attributes and content.
$discord
The Discord client.
protected
Discord
$discord
Client.
$factory
The factory.
protected
Factory
$factory
Factory.
$fillable
The parts fillable attributes.
protected
array<string|int, mixed>
$fillable
= ['name', 'url', 'type', 'created_at', 'timestamps', 'application_id', 'status_display_type', 'details', 'details_url', 'state', 'state_url', 'emoji', 'party', 'assets', 'secrets', 'instance', 'flags', 'buttons']
The array of attributes that can be mass-assigned.
Tags
$hidden
Attributes that are hidden from debug info.
protected
array<string|int, mixed>
$hidden
= []
Attributes that are hidden from public.
$http
The HTTP client.
protected
Http
$http
Client.
$repositories
An array of repositories that can exist in a part.
protected
array<string|int, mixed>
$repositories
= []
Repositories.
$repositories_cache
An array of repositories.
protected
array<string|int, mixed>
$repositories_cache
= []
$visible
Attributes which are visible from debug info.
protected
array<string|int, mixed>
$visible
= []
Methods
__construct()
Create a new part instance.
public
__construct(Discord $discord[, array<string|int, mixed> $attributes = [] ][, bool $created = false ]) : mixed
Parameters
- $discord : Discord
-
The Discord client.
- $attributes : array<string|int, mixed> = []
-
An array of attributes to build the part.
- $created : bool = false
-
Whether the part has already been created.
__debugInfo()
Debug representation for `var_dump()`.
public
__debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>__get()
Handles dynamic get calls onto the part.
public
__get(string $key) : mixed
Parameters
- $key : string
-
The attributes key.
Tags
Return values
mixed —The value of the attribute.
__isset()
Handles isset() and empty() on the part's magic properties.
public
__isset(string $key) : bool
A property is set when reading it gives a value other than null, whether it is stored, computed by a mutator or a child repository, as for a declared property. Without this, isset() is false for every attribute and empty() is true.
Parameters
- $key : string
-
The attribute key.
Tags
Return values
bool —Whether reading the property gives a value other than null.
__serialize()
The raw attributes, for PHP native serialization.
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__set()
Handles dynamic set calls onto the part.
public
__set(string $key, mixed $value) : void
Parameters
- $key : string
-
The attributes key.
- $value : mixed
-
The attributes value.
Tags
__toString()
Converts the activity to a string.
public
__toString() : string
Return values
string__unserialize()
Restores attributes from PHP native unserialization.
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
fetch()
Fetches any missing information about the part from Discord's servers.
public
fetch() : PromiseInterface<string|int, static>
Tags
Return values
PromiseInterface<string|int, static>fill()
Fills the parts attributes from an array.
public
fill(array<string|int, mixed> $attributes) : void
Parameters
- $attributes : array<string|int, mixed>
-
An array of attributes to build the part.
Tags
getConstants()
Returns an array of constant names and their values.
public
getConstants() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An associative array where keys are constant names and values are their values.
getCreatableAttributes()
Returns the attributes needed to create.
public
getCreatableAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getDiscord()
Get the Discord instance that owns this Part.
public
getDiscord() : Discord
Return values
DiscordgetPublicAttributes()
Returns an array of public attributes.
public
getPublicAttributes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
getRawAttributes()
Returns an array of raw attributes.
public
getRawAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —Raw attributes.
getRepository()
Gets the originating repository of the part.
public
getRepository() : AbstractRepository|null
Tags
Return values
AbstractRepository|null —The repository, or null if required part data is missing.
getRepositoryAttributes()
Gets the attributes to pass to repositories.
public
getRepositoryAttributes() : array<string|int, mixed>
Note: The order matters for repository tree (top to bottom).
Return values
array<string|int, mixed> —Attributes.
getUpdatableAttributes()
Returns the updatable attributes.
public
getUpdatableAttributes() : array<string|int, mixed>
To be used with fields that can be changed after a part has already been created.
Return values
array<string|int, mixed>isPartial()
Whether the part is considered partial i.e. missing information which can be fetched from Discord.
public
isPartial() : bool
Return values
booljsonSerialize()
Provides data when the part is encoded into JSON. Used for JsonSerializable.
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
offsetExists()
Checks if an attribute exists via key. Used for ArrayAccess.
public
offsetExists(string $key) : bool
Parameters
- $key : string
-
The attribute key.
Tags
Return values
bool —Whether reading the offset gives a value other than null.
offsetGet()
Gets an attribute via key. Used for ArrayAccess.
public
offsetGet(string $key) : mixed
Parameters
- $key : string
-
The attribute key.
Tags
Attributes
- #[ReturnTypeWillChange]
offsetSet()
Sets an attribute via key. Used for ArrayAccess.
public
offsetSet(string $key, mixed $value) : void
Parameters
- $key : string
-
The attribute key.
- $value : mixed
-
The attribute value.
Tags
offsetUnset()
Unsets an attribute via key. Used for ArrayAccess.
public
offsetUnset(string $key) : void
Parameters
- $key : string
-
The attribute key.
save()
Save the part with its originating repository.
public
save([string|null $reason = null ]) : PromiseInterface<string|int, Part>
Parameters
- $reason : string|null = null
-
The reason for the audit log, if supported.
Tags
Return values
PromiseInterface<string|int, Part> —Resolves with the saved part.
serialize()
Serializes the data. Used for Serializable.
public
serialize() : ?string
Return values
?string —A string of serialized data.
unserialize()
Unserializes some data and stores it. Used for Serializable.
public
unserialize(string $data) : void
Parameters
- $data : string
-
Some serialized data.
Tags
afterConstruct()
Called after the part has been constructed.
protected
afterConstruct() : void
attributeCarbonHelper()
Helps with getting ISO8601 timestamp attributes.
protected
attributeCarbonHelper(string $key) : Carbon|null
Parameters
- $key : string
-
The attribute key.
Tags
Return values
Carbon|nullattributeCollectionHelper()
Helps with getting Part attributes.
protected
attributeCollectionHelper(string $key, string $class[, ?string $discrim = 'id' ][, ?array<string|int, mixed> $extraData = [] ]) : ExCollectionInterface
Parameters
- $key : string
-
The attribute key.
- $class : string
-
The attribute class.
- $discrim : ?string = 'id'
-
The attribute discriminator.
- $extraData : ?array<string|int, mixed> = []
Tags
Return values
ExCollectionInterfaceattributePartHelper()
Helps with getting Part attributes.
protected
attributePartHelper(string $key, string $class[, array<string|int, mixed> $extraData = [] ]) : Part|null
Parameters
- $key : string
-
The attribute key.
- $class : string
-
The attribute class.
- $extraData : array<string|int, mixed> = []
-
Extra data to pass to the part constructor.
Tags
Return values
Part|nullattributeTypedCollectionHelper()
Helps with getting Part attributes for classes with extended types.
protected
attributeTypedCollectionHelper(string $class, string $key) : ExCollectionInterface
Parameters
- $class : string
-
The attribute class.
- $key : string
-
The attribute key.
Return values
ExCollectionInterfacecheckForGetMutator()
Checks if there is a get mutator present.
protected
checkForGetMutator(string $key) : string|false
Parameters
- $key : string
-
The attribute name to check.
Tags
Return values
string|false —Either a string if it is a method or false.
checkForSetMutator()
Checks if there is a set mutator present.
protected
checkForSetMutator(string $key) : string|false
Parameters
- $key : string
-
The attribute name to check.
Tags
Return values
string|false —Either a string if it is a method or false.
getAssetsAttribute()
Gets the assets object of the activity.
protected
getAssetsAttribute() : Assets|null
Return values
Assets|nullgetAttribute()
Gets an attribute on the part.
protected
getAttribute(string $key) : mixed
Parameters
- $key : string
-
The key to the attribute.
Tags
Return values
mixed —Either the attribute if it exists or void.
getButtonsAttribute()
Gets the buttons array of the activity.
protected
getButtonsAttribute() : ExCollectionInterface<string|int, Button>|array<string|int, Button>|null
Return values
ExCollectionInterface<string|int, Button>|array<string|int, Button>|nullgetCreatedAtAttribute()
Gets the created at timestamp.
protected
getCreatedAtAttribute() : Carbon|null
Tags
Return values
Carbon|nullgetEmojiAttribute()
Gets the emoji object of the activity.
protected
getEmojiAttribute() : Emoji|null
Return values
Emoji|nullgetPartyAttribute()
Gets the party object of the activity.
protected
getPartyAttribute() : Party|null
Return values
Party|nullgetSecretsAttribute()
Gets the secrets object of the activity.
protected
getSecretsAttribute() : Secrets|null
Return values
Secrets|nullgetTimestampsAttribute()
Gets the timestamps object of the activity.
protected
getTimestampsAttribute() : Timestamps|null
Return values
Timestamps|nullmakeOptionalAttributes()
Return key-value attributes if it has been filled.
protected
makeOptionalAttributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
To be used with fields marked "optional?" from the API.
Parameters
- $attributes : array<string|int, mixed>
-
Names of optional attribute
Return values
array<string|int, mixed>setAttribute()
Sets an attribute on the part.
protected
setAttribute(string $key, mixed $value) : void
Parameters
- $key : string
-
The key to the attribute.
- $value : mixed
-
The value of the attribute.
studly()
Converts a string to studlyCase.
private
static studly(string $string) : string
This is a port of updated Laravel's implementation, a non-regex with static cache. The Discord\studly() is kept due to unintended bug and we do not want to introduce BC by replacing it. This method is private static as we may move it outside this class in future.
Parameters
- $string : string
-
The string to convert.