Skip to main content

Activity

Struct Activity 

Source
#[non_exhaustive]
pub struct Activity {
Show 18 fields pub name: CompactString, pub kind: ActivityType, pub url: Option<CompactString>, pub created_at: Option<Timestamp>, pub timestamps: Option<ActivityTimestamps>, pub application_id: Option<ApplicationId>, pub status_display_type: Option<StatusDisplayType>, pub details: Option<CompactString>, pub details_url: Option<CompactString>, pub state: Option<CompactString>, pub state_url: Option<CompactString>, pub emoji: Option<ActivityEmoji>, pub party: Option<ActivityParty>, pub assets: Option<Box<ActivityAssets>>, pub secrets: Option<Box<ActivitySecrets>>, pub instance: bool, pub flags: ActivityFlags, pub buttons: Vec<CompactString>,
}
Expand description

An activity: a game, stream, song, custom status, … shown in a user’s presence.

Bots can only set name, state, kind and url (see Activity::new).

discord.js counterpart: Activity.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: CompactString

The activity’s name.

§kind: ActivityType

The kind of activity.

§url: Option<CompactString>

The stream URL (Streaming; Twitch and YouTube only).

§created_at: Option<Timestamp>

When the activity was added to the user’s session.

§timestamps: Option<ActivityTimestamps>

When the game started and/or ends.

§application_id: Option<ApplicationId>

The game’s application.

§status_display_type: Option<StatusDisplayType>

Which field the member list shows as status text.

§details: Option<CompactString>

What the player is doing.

§details_url: Option<CompactString>

The URL linked from the details text.

§state: Option<CompactString>

The party status, or the text of a custom status.

§state_url: Option<CompactString>

The URL linked from the state text.

§emoji: Option<ActivityEmoji>

The emoji of a custom status.

§party: Option<ActivityParty>

The player’s party.

§assets: Option<Box<ActivityAssets>>

The images and their hover texts.

§secrets: Option<Box<ActivitySecrets>>

The Rich Presence secrets for joining and spectating.

§instance: bool

Whether the activity is an instanced game session.

§flags: ActivityFlags

What the activity supports.

§buttons: Vec<CompactString>

The labels of the custom buttons (max 2; bots cannot see the URLs).

Implementations§

Source§

impl Activity

Source

pub fn new(kind: ActivityType, name: impl Into<CompactString>) -> Self

Creates an activity with the fields bots can set: a name and kind (set state for a custom status text, url for a stream).

discord.js counterpart: ActivitiesOptions.

Source

pub fn playing(name: impl Into<CompactString>) -> Self

“Playing {name}”.

discord.js counterpart: ActivitiesOptions with type: ActivityType.Playing.

§Examples
use djs_model::gateway::{Activity, ActivityType};

let activity = Activity::playing("with Rust");
assert_eq!((activity.kind, activity.name.as_str()), (ActivityType::Playing, "with Rust"));
Source

pub fn streaming( name: impl Into<CompactString>, url: impl Into<CompactString>, ) -> Self

“Streaming {name}”, linking to url. Discord only accepts https://twitch.tv/ and https://youtube.com/ URLs.

discord.js counterpart: ActivitiesOptions with type: ActivityType.Streaming.

§Examples
use djs_model::gateway::Activity;

let activity = Activity::streaming("Rust live", "https://twitch.tv/example");
assert_eq!(
    serde_json::to_string(&activity).unwrap(),
    r#"{"name":"Rust live","type":1,"url":"https://twitch.tv/example"}"#
);
Source

pub fn listening(name: impl Into<CompactString>) -> Self

“Listening to {name}”.

discord.js counterpart: ActivitiesOptions with type: ActivityType.Listening.

Source

pub fn watching(name: impl Into<CompactString>) -> Self

“Watching {name}”.

discord.js counterpart: ActivitiesOptions with type: ActivityType.Watching.

Source

pub fn competing(name: impl Into<CompactString>) -> Self

“Competing in {name}”.

discord.js counterpart: ActivitiesOptions with type: ActivityType.Competing.

Source

pub fn custom(text: impl Into<CompactString>) -> Self

A custom status showing text (stored in state; the name is "Custom Status", as Discord’s clients send).

discord.js counterpart: ActivitiesOptions with type: ActivityType.Custom.

§Examples
use djs_model::gateway::Activity;

let activity = Activity::custom("Fixing bugs");
assert_eq!(activity.state.as_deref(), Some("Fixing bugs"));

Trait Implementations§

Source§

impl Clone for Activity

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Activity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Activity

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Activity

Source§

impl PartialEq for Activity

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Activity

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Activity

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.