13 releases

0.4.0 Oct 16, 2023
0.3.0 Dec 6, 2018
0.2.4 Dec 4, 2018
0.2.3 Apr 8, 2018
0.1.5 Mar 28, 2018

#5 in #rpc-client

Download history 41/week @ 2023-12-11 48/week @ 2023-12-18 82/week @ 2023-12-25 73/week @ 2024-01-01 49/week @ 2024-01-08 34/week @ 2024-01-15 24/week @ 2024-01-22 47/week @ 2024-01-29 31/week @ 2024-02-05 38/week @ 2024-02-12 68/week @ 2024-02-19 75/week @ 2024-02-26 63/week @ 2024-03-04 78/week @ 2024-03-11 76/week @ 2024-03-18 74/week @ 2024-03-25

296 downloads per month
Used in 3 crates

MIT license

33KB
872 lines

Build status crates.io crates.io Discord

Discord RPC Client

Discord RPC client for Rust

Installation

Add this to your Cargo.toml:

[dependencies]
discord-rpc-client = "^0.4"

Example

use std::{env, thread, time};
use discord_rpc_client::{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(425407036495495169);

    // 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.

Contributions

See CONTRIBUTING.md

Dependencies

~1.4–2.5MB
~49K SLoC