Crates.io | discord-rpc-client |
lib.rs | discord-rpc-client |
version | 0.4.0 |
source | src |
created_at | 2018-03-22 14:45:48.150287 |
updated_at | 2023-10-16 20:53:03.589023 |
description | A Rust client for Discord RPC. |
homepage | |
repository | https://github.com/yera-systems/discord-rpc-client.rs.git |
max_upload_size | |
id | 56897 |
size | 57,927 |
Discord RPC client for Rust
Add this to your Cargo.toml
:
[dependencies]
discord-rpc-client = "^0.4"
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.
See CONTRIBUTING.md