27 releases (5 stable)

1.2.0 May 1, 2024
1.1.1 Mar 13, 2024
0.5.18 Aug 21, 2023
0.5.15 Jun 13, 2023
0.5.5 Jul 8, 2022

#303 in Network programming

Download history 54/week @ 2024-03-25 111/week @ 2024-04-01 155/week @ 2024-04-08 47/week @ 2024-04-15 55/week @ 2024-04-22 185/week @ 2024-04-29 34/week @ 2024-05-06 31/week @ 2024-05-13 59/week @ 2024-05-20 34/week @ 2024-05-27 55/week @ 2024-06-03 55/week @ 2024-06-10 94/week @ 2024-06-17 53/week @ 2024-06-24 133/week @ 2024-07-01 32/week @ 2024-07-08

319 downloads per month
Used in 4 crates

MIT license

57KB
1.5K SLoC

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 = "1.2"

or run:

cargo add discord-presence

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

~6–31MB
~458K SLoC