pub struct DiscordIPC { /* private fields */ }Expand description
Basic Discord rich presence IPC implementation.
Implementations§
Source§impl DiscordIPC
impl DiscordIPC
Sourcepub async fn new(client_id: &str) -> Result<Self>
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?
More 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}Sourcepub async fn run(&mut self) -> Result<()>
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?
More 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}Sourcepub async fn wait(&mut self) -> Result<()>
pub async fn wait(&mut self) -> Result<()>
Waits for response from IPC task; can be used to run the client indefinitely.
Sourcepub async fn set_activity(&mut self, details: &str, state: &str) -> Result<()>
pub async fn set_activity(&mut self, details: &str, state: &str) -> Result<()>
Sets a tiny Discord rich presence activity.
Examples found in repository?
More 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§
impl Freeze for DiscordIPC
impl !RefUnwindSafe for DiscordIPC
impl Send for DiscordIPC
impl Sync for DiscordIPC
impl Unpin for DiscordIPC
impl !UnwindSafe for DiscordIPC
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more