Skip to main content

DiscordIPC

Struct DiscordIPC 

Source
pub struct DiscordIPC { /* private fields */ }
Expand description

Basic Discord rich presence IPC implementation.

Implementations§

Source§

impl DiscordIPC

Source

pub async fn new(client_id: &str) -> Result<Self>

Given a client ID, create a new DiscordIPC instance. Needs to have Discord running for successful execution.

Examples found in repository?
examples/indefinite.rs (line 7)
6async fn main() {
7    let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
8
9    client.run().await.unwrap();
10    client.set_activity("this runs", "forever").await.unwrap();
11    client.wait().await.unwrap();
12}
More examples
Hide additional examples
examples/timed.rs (line 10)
9async fn main() {
10    let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
11
12    client.run().await.unwrap();
13
14    client
15        .set_activity("this runs", "for ten seconds")
16        .await
17        .unwrap();
18    sleep(Duration::from_secs(5)).await;
19    client.set_activity("believe it", "or not").await.unwrap();
20    sleep(Duration::from_secs(5)).await;
21}
Source

pub async fn run(&mut self) -> Result<()>

Starts off the connection with Discord. This includes performing a handshake, waiting for READY and starting the IPC response loop.

Examples found in repository?
examples/indefinite.rs (line 9)
6async fn main() {
7    let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
8
9    client.run().await.unwrap();
10    client.set_activity("this runs", "forever").await.unwrap();
11    client.wait().await.unwrap();
12}
More examples
Hide additional examples
examples/timed.rs (line 12)
9async fn main() {
10    let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
11
12    client.run().await.unwrap();
13
14    client
15        .set_activity("this runs", "for ten seconds")
16        .await
17        .unwrap();
18    sleep(Duration::from_secs(5)).await;
19    client.set_activity("believe it", "or not").await.unwrap();
20    sleep(Duration::from_secs(5)).await;
21}
Source

pub async fn wait(&mut self) -> Result<()>

Waits for response from IPC task; can be used to run the client indefinitely.

Examples found in repository?
examples/indefinite.rs (line 11)
6async fn main() {
7    let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
8
9    client.run().await.unwrap();
10    client.set_activity("this runs", "forever").await.unwrap();
11    client.wait().await.unwrap();
12}
Source

pub async fn set_activity(&mut self, details: &str, state: &str) -> Result<()>

Sets a tiny Discord rich presence activity.

Examples found in repository?
examples/indefinite.rs (line 10)
6async fn main() {
7    let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
8
9    client.run().await.unwrap();
10    client.set_activity("this runs", "forever").await.unwrap();
11    client.wait().await.unwrap();
12}
More examples
Hide additional examples
examples/timed.rs (line 15)
9async fn main() {
10    let mut client = DiscordIPC::new("1463450870480900160").await.unwrap();
11
12    client.run().await.unwrap();
13
14    client
15        .set_activity("this runs", "for ten seconds")
16        .await
17        .unwrap();
18    sleep(Duration::from_secs(5)).await;
19    client.set_activity("believe it", "or not").await.unwrap();
20    sleep(Duration::from_secs(5)).await;
21}

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.