PresenceForge
A Rust library for Discord Rich Presence that actually works without the headaches. No more fighting with the Discord SDK or dealing with complex C bindings.
Note: This is currently in development (v0.1.0-dev). Things might break This is a learning/hobby project. Features and APIs may change in future versions.
Documentation
- Getting Started Guide - Installation and first steps
- API Reference - Complete API documentation
- Activity Builder Reference - Detailed guide to all fields
- Async Runtimes Guide - Using async/await with Tokio, async-std, or smol
- Error Handling Guide - Proper error handling patterns
- FAQ & Troubleshooting - Common questions and solutions
Want to build your own RPC client?
- Discord RPC from Scratch - this is What I found while building this library. I could be wrong about some things, so feel free to correct me!
What Works
- Linux and macOS (Unix domain sockets)
- Windows support (named pipes)
- Flatpak Discord support (automatic detection)
- Basic Rich Presence activities
- Activity builder pattern
- Images, buttons, and timestamps
- Async support with runtime-agnostic design
- Support for tokio, async-std, and smol
- Flexible pipe/socket selection
Quick Start
Add PresenceForge to your Cargo.toml:
[]
= "0.1.0-dev"
For async support, add one of the runtime features:
[]
= { = "0.1.0-dev", = ["tokio-runtime"] }
# OR
= { = "0.1.0-dev", = ["async-std-runtime"] }
# OR
= { = "0.1.0-dev", = ["smol-runtime"] }
Basic Usage (Synchronous)
use ActivityBuilder;
use DiscordIpcClient;
Async Usage with Tokio
use ;
async
Async Usage with async-std
use ;
use task;
use Duration;
async
Async Usage with smol
use ;
use Duration;
Examples
Game Integration
use ActivityBuilder;
use DiscordIpcClient;
let activity = new
.state
.details
.start_timestamp_now
.large_image
.large_text
.small_image
.small_text
.button
.button
.build;
client.set_activity?;
Developer Tools
let activity = new
.state
.details
.start_timestamp_now
.large_image
.large_text
.small_image
.small_text
.button
.build;
Getting Your Discord Application ID
- Go to the Discord Developer Portal
- Create a new application or select an existing one
- Copy the Application ID from the General Information page
- (Optional) Upload images in the Rich Presence Art Assets section
Configuration Methods
All examples support three ways to provide your Discord Client ID:
1. Command-line Argument (Recommended for testing)
2. Environment Variable
DISCORD_CLIENT_ID=YOUR_CLIENT_ID
3. .env File (Recommended for development)
# Copy the example file
# Edit .env and add your client ID
# DISCORD_CLIENT_ID=your_client_id_here
# Then run any example
Priority Order: Command-line argument → Environment variable → .env file
Platform Support
| Platform | IPC Method | Status |
|---|---|---|
| Linux | Unix Domain Sockets | [x] |
| macOS | Unix Domain Sockets | [x] |
| Windows | Named Pipes | [x] |
API Reference
Client
DiscordIpcClient::new(client_id)- Create a new clientclient.connect()- Connect to Discordclient.set_activity(activity)- Set Rich Presence activityclient.clear_activity()- Clear current activity
Activity Builder
The ActivityBuilder provides a fluent interface for creating activities:
new
.state // What the player is doing
.details // Additional context
.start_timestamp_now // Start time (current)
.start_timestamp // Start time (custom)
.end_timestamp // End time
.large_image // Large image asset
.large_text // Large image hover text
.small_image // Small image asset
.small_text // Small image hover text
.button // Clickable button (max 2)
.party // Party size (current, max)
.build
Running Examples
For detailed information about all available examples and configuration options, see the Examples README.
Clone the repository and run the included examples:
# Basic example (synchronous)
# Game demo with dynamic status
# Developer coding status
# Custom activity without builder
# Async example with Tokio
# Async example with async-std
# Async example with smol
# Complete builder reference - Shows ALL ActivityBuilder options
# Connection retry and error handling
# Pipe selection and discovery
Or use the .env file method (recommended for development):
# Set up .env file once
# Edit .env and add: DISCORD_CLIENT_ID=your_client_id_here
# Then run examples without specifying client ID
Note: Replace YOUR_CLIENT_ID with your actual Discord application ID, or use the .env file method for convenience.
Error Handling
PresenceForge uses the Result type for error handling:
use DiscordIpcError;
use DiscordIpcClient;
match client.connect
TODO
- Better error messages
- Party/lobby functionality (partial implementation)
- Async support (tokio, async-std, and smol)
- More comprehensive examples
- Publish to crates.io
- CI/CD pipeline
- Proper documentation
- Connection retry logic with exponential backoff
- Activity validation
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.