Crates.io | rust-discord-activity |
lib.rs | rust-discord-activity |
version | 0.3.1 |
source | src |
created_at | 2023-12-30 08:54:46.177477 |
updated_at | 2024-10-16 10:39:35.392549 |
description | A lightweight library to control Discord Rich Presence |
homepage | |
repository | https://github.com/DylanCa/Rust-Discord-Activity |
max_upload_size | |
id | 1083991 |
size | 23,896 |
A lightweight Rust library to control Discord Rich Presence
Rust Discord Activity is available directly on crates.io:
cargo add rust-discord-activity
Et voilĂ !
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);
And voilĂ ! This sets-up a new Activity for the current Discord user:
For the moment, the library only works with MacOS and local Discord application.