#discord #rpc #ipc

discord-presence

A Rust client for Discord RPC

13 releases

new 0.5.7 Aug 5, 2022
0.5.6 Aug 1, 2022
0.5.5 Jul 8, 2022
0.5.4 Jun 18, 2022
0.4.4 Apr 17, 2022

#106 in Game dev

Download history 164/week @ 2022-04-17 19/week @ 2022-04-24 47/week @ 2022-05-01 39/week @ 2022-05-08 147/week @ 2022-05-15 33/week @ 2022-05-22 155/week @ 2022-05-29 101/week @ 2022-06-05 41/week @ 2022-06-12 26/week @ 2022-06-19 7/week @ 2022-06-26 37/week @ 2022-07-03 72/week @ 2022-07-10 28/week @ 2022-07-17 51/week @ 2022-07-24 73/week @ 2022-07-31

233 downloads per month
Used in bevy-discord-presence

MIT license

36KB
904 lines

Discord RPC

crates.io crates.io docs.rs

Discord RPC client for Rust forked from Discord RPC Client

Note: If you are looking to add this into a game, check out the Bevy implementation

Installation

Add this to your Cargo.toml:

[dependencies]
discord-presence = "0.5"

or run:

cargo add discord-presence

if you have cargo-edit installed

Example

use std::{env, thread, time};
use discord_presence::{Client, Event};

fn main() {
    // Get our main status message
    let state_message = env::args().nth(1).expect("Requires at least one argument");

    // Create the client
    let mut drpc = Client::new(1003450375732482138);

    // Register event handlers with the corresponding methods
    drpc.on_ready(|_ctx| {
        println!("ready?");
    });

    // or

    drpc.on_event(Event::Ready, |ctx| {
        println!("READY!");
    });

    // Start up the client connection, so that we can actually send and receive stuff
    drpc.start();

    // Set the activity
    drpc.set_activity(|act| act.state(state_message))
        .expect("Failed to set activity");

    // Wait 10 seconds before exiting
    thread::sleep(time::Duration::from_secs(10));
}

More examples can be found in the examples directory.

Changelog

See CHANGELOG.md

Contributions

See CONTRIBUTING.md

Dependencies

~1.8–7.5MB
~132K SLoC