A Rust library to deal with Discord Activity Rich Presence
Find a file
AmokDev 176b76ee45 Update Cargo.toml
change version to 1.0.0
2025-06-08 11:24:48 +00:00
src readme update 2025-06-07 23:51:22 +03:00
.gitignore Added .gitignore to project 2023-12-29 02:49:17 +01:00
Cargo.toml Update Cargo.toml 2025-06-08 11:24:48 +00:00
LICENSE Обновить LICENSE 2025-03-18 08:58:22 +00:00
README.md readme update 2025-06-08 00:12:28 +03:00
README_EN.md update readme 2025-06-08 00:14:54 +03:00

Localizations

EN | RU

Rust Discord Activity

A lightweight Rust library to control Discord Rich Presence for Windows, Linux and MacOS

Author of the idea

Installation

cargo add --git https://git.amok.dev/AmokDev/rust-discord-rpc

How to use

  1. Instantiate a new DiscordClient
  2. Create your Activity and set desired data using provided structs
  3. Create a new Payload with your Activity
  4. Send your Payload through the DiscordClient

Example

let mut client = DiscordClient::new("<application_id>");

let _ = client.connect();

let limg = Some(String::from("https://placehold.co/600x400/png"));
let simg = Some(String::from("https://placehold.co/200x100/png"));
let asset = Asset::new(limg, None, simg, None);
let now_in_millis = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis();
let timestamp = Timestamp::new(Some(now_in_millis - 10000), None);

let party = Party::new(None, Some((2, 4)));
let mut button_vec = vec![];
button_vec.push(Button::new("First Button".into(), "https://google.com".into()));
button_vec.push(Button::new("Second Button".into(), "https://yahoo.com".into()));

let mut activity = Activity::new();

activity
    .set_state(Some("This is State".into()))
    .set_activity_type(Some(ActivityType::LISTENING))
    .set_details(Some("This is Details".parse().unwrap()))
    .set_timestamps(Some(timestamp))
    .set_assets(Some(asset))
    .set_party(Some(party))
    .set_instance(Some(true))
    .set_buttons(Some(button_vec));

let payload = Payload::new(EventName::Activity, EventData::Activity(activity));

let _ = client.send_payload(payload);

This sets-up a new Activity for the current Discord user:

Discord Rich Presence

Thanks for support

Testers

Windows MacOS Linux
AmokDev (me) hellkarm doxbiner