https://github.com/vyfor/kpresence
📦 Lightweight Kotlin Multiplatform library for Discord Rich Presence
https://github.com/vyfor/kpresence
discord discord-presence discord-rpc java jvm kotlin kotlin-native presence rich rich-presence rpc
Last synced: 16 days ago
JSON representation
📦 Lightweight Kotlin Multiplatform library for Discord Rich Presence
- Host: GitHub
- URL: https://github.com/vyfor/kpresence
- Owner: vyfor
- License: mit
- Created: 2024-03-11T12:44:01.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-10T15:59:38.000Z (about 2 months ago)
- Last Synced: 2025-03-24T14:44:33.928Z (about 1 month ago)
- Topics: discord, discord-presence, discord-rpc, java, jvm, kotlin, kotlin-native, presence, rich, rich-presence, rpc
- Language: Kotlin
- Homepage:
- Size: 247 KB
- Stars: 15
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🧩 KPresence
**📦 A lightweight, cross-platform [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html) library for interacting with Discord Rich Presence.**
## 💎 Features
- Cross-platform compatibility (Windows, Linux, macOS)
- Fast and user-friendly
- Offers DSL support
- Provides both JVM and Native implementations
- Validates the activity fields before sending them
- Supports Flatpak and Snap installations on Linux
- Ability to extend and override the default search paths## 🔌 Requirements
- **Java**: `16 or later` (only for use within the JVM environment)## ⚙️ Installation
```gradle
dependencies {
implementation("io.github.vyfor:kpresence:0.6.5")
}
```## ✨ Examples
### Initial connection and presence updates
```kt
val client = RichClient(CLIENT_ID)
client.connect()client.update {
type = ActivityType.GAME
details = "Exploring Kotlin Native"
state = "Writing code"
timestamps {
start = now() - 3600_000
end = now() + 3600_000
}
party {
id = "myParty"
size(current = 1, max = 5)
}
assets {
largeImage = "kotlin_logo"
largeText = "Kotlin"
smallImage = "jetbrains_logo"
smallText = "JetBrains"
}
secrets {
join = "joinSecret"
spectate = "spectateSecret"
match = "matchSecret"
}
button("Learn more", "https://kotlinlang.org/")
button("Try it yourself", "https://play.kotlinlang.org/")
}
```### Event handling
```kt
val client = RichClient(CLIENT_ID)client.on {
update(activity)
}client.on {
logger?.info("Updated rich presence")
}client.on {
connect(shouldBlock = true) // Attempt to reconnect
}client.connect(shouldBlock = false)
```### Logging
```kt
val client = RichClient(CLIENT_ID)
client.logger = ILogger.default()
```