31 releases (9 stable)

1.5.0 Jan 6, 2025
1.4.1 Nov 27, 2024
1.3.1 Sep 27, 2024
1.2.0 May 1, 2024
0.5.5 Jul 8, 2022

#178 in Web programming

Download history 38/week @ 2024-10-21 134/week @ 2024-10-28 183/week @ 2024-11-04 265/week @ 2024-11-11 283/week @ 2024-11-18 402/week @ 2024-11-25 149/week @ 2024-12-02 250/week @ 2024-12-09 185/week @ 2024-12-16 364/week @ 2024-12-23 120/week @ 2024-12-30 377/week @ 2025-01-06 327/week @ 2025-01-13 170/week @ 2025-01-20 149/week @ 2025-01-27 245/week @ 2025-02-03

946 downloads per month
Used in 6 crates

MIT license

64KB
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.5"

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

~5–28MB
~402K SLoC