#rich-presence #ipc #discord #discord-api

discord-rich-presence

A simple, cross-platform crate for interfacing with Discord's IPC

14 releases

0.2.5 Sep 28, 2024
0.2.4 May 16, 2024
0.2.3 Sep 17, 2022
0.2.1 Jul 7, 2022
0.1.7 Jul 21, 2021

#1397 in Web programming

Download history 828/week @ 2024-07-26 835/week @ 2024-08-02 1031/week @ 2024-08-09 1500/week @ 2024-08-16 1215/week @ 2024-08-23 981/week @ 2024-08-30 1047/week @ 2024-09-06 895/week @ 2024-09-13 888/week @ 2024-09-20 1272/week @ 2024-09-27 991/week @ 2024-10-04 939/week @ 2024-10-11 922/week @ 2024-10-18 732/week @ 2024-10-25 832/week @ 2024-11-01 436/week @ 2024-11-08

3,081 downloads per month
Used in 14 crates (11 directly)

MIT license

26KB
512 lines

Discord Rich Presence

crates.io Docs

A simple, cross-platform crate to connect and send data to Discord's IPC. Special attention is given to sending rich presence data.

Example

use discord_rich_presence::{activity, DiscordIpc, DiscordIpcClient};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = DiscordIpcClient::new("<some application ID>")?;

    client.connect()?;
    client.set_activity(activity::Activity::new()
        .state("foo")
        .details("bar")
    )?;
    client.close()?;

    Ok(())
}

Running example on the CLI

The repository comes with an example you can run with cargo to set a dummy activity. Just provide a valid Client ID as the argument:

cargo run --example presence <CLIENT_ID>

lib.rs:

This library provides easy access to the Discord IPC.

It provides implementations for both Unix and Windows operating systems, with both implementations using the same API. Thus, this crate can be used in a platform-agnostic manner.

Hello world

use discord_rich_presence::{activity, DiscordIpc, DiscordIpcClient};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = DiscordIpcClient::new("<some client id>")?;
    client.connect()?;

    let payload = activity::Activity::new().state("Hello world!");
    client.set_activity(payload)?;
}

Dependencies

~1–2MB
~43K SLoC