Expand description
§Discord Social RPC
A Rust library for Discord Rich Presence using the sdk.social_layer_presence
OAuth2 scope. Provides a synchronous API — no async/await needed.
§Quick Start — Rich Presence
use discord_social_rpc::{
DiscordSocialRpc, Activity, ActivityType, Assets,
};
let client = DiscordSocialRpc::new("your_app_id").unwrap();
let rpc = client.create_new_client("your_oauth2_token").unwrap();
rpc.set_activity(
&Activity::new()
.set_state("Playing Rust")
.set_details("Building a library")
.set_activity_type(ActivityType::Listening)
.set_assets(Assets::new().set_large_image("https://example.com/banner.png"))
).unwrap();
rpc.start_activity().unwrap();
println!("{:?}", rpc.activity_status());
rpc.stop_activity().unwrap();§Admin — Token Refresh & Code Exchange
use discord_social_rpc::DiscordSocialRpcAdmin;
// Create the admin with your Discord client_id and client_secret
let admin = DiscordSocialRpcAdmin::new("your_client_id", "your_client_secret")
.expect("Failed to create admin");
// Refresh a user's OAuth2 token
let refresh_resp = admin.refresh_user_token("user_refresh_token")
.expect("Failed to refresh token");
println!("New access token: {}", refresh_resp.access_token);
// Exchange an authorization code for tokens
let exchange_resp = admin.exchange_code("auth_code", "https://your-redirect-uri")
.expect("Failed to exchange code");
println!("Access token: {}", exchange_resp.access_token);Re-exports§
pub use utils::CodeExchangeResponse;pub use utils::TokenRefreshResponse;
Modules§
Structs§
- Activity
- A Discord Rich Presence activity, built using the builder pattern.
- Assets
- Assets (images) for a Discord activity.
- Discord
RpcClient - A client that manages a Discord Rich Presence connection.
- Discord
Social Rpc - The entry point for Discord Social RPC.
- Discord
Social RpcAdmin - Admin interface for Discord
OAuth2operations. - Timestamps
- Timestamps for an activity (start and/or end).
Enums§
- Activity
Status - Represents the current state of the Discord Rich Presence connection.
- Activity
Type - Discord activity type as defined by Gateway API.
- Error
- Errors that can occur during Discord RPC operations.
- Presence
Status - User presence status on Discord.