3.9 KiB
discord-game-presence
Shows the game you're playing in Discord ("Playing Genshin Impact", with the game's icon and a timer) when Discord can't detect it by itself because it runs in a sandbox: Flatpak, Snap or firejail.
Discord normally detects games by looking at running processes. In a sandbox with its own PID namespace it sees only
its own processes, so it never notices a game. discord-game-presence runs outside the sandbox, watches /proc, and
reports the game to Discord through its local Rich Presence socket, using the game's official Discord application ID.
Discord then shows it the same way as a game it detected itself.
How it works
- Downloads Discord's list of detectable games (
/api/v9/applications/detectable, about 13 MB) to~/.cache/discord-game-presence/detectable.jsonand refreshes it once a week. If a download fails, the old copy is kept. - Every 5 seconds, reads the command line of every process and matches it:
- Steam games by Steam app ID: Steam starts each game under a
reaper SteamLaunch AppId=Nprocess that lives as long as the game, and Discord's list records each game's Steam ID. This works the same for native and Proton games. - Other games (Wine, launchers) by executable: the program path (
argv[0], with\turned into/) must end with one of the game's executable names from Discord's list, at a folder boundary. Entries Discord marks as launchers are skipped. Only Windows names are used by default, since Linux names can match ordinary tools.
- Steam games by Steam app ID: Steam starts each game under a
- Shows one game at a time: the one that started first, until it exits. The timer counts from the game's start.
- Connects to Discord only while a game runs, and closes the connection when it exits, which clears the activity. If Discord isn't running or restarts, it retries on the next scan.
Requirements
-
python(3.11 or newer; standard library only) -
Discord's IPC socket reachable from outside the sandbox. Flatpak (
$XDG_RUNTIME_DIR/app/com.discordapp.Discord/) and Snap ($XDG_RUNTIME_DIR/snap.discord/) sockets are found as they are. firejail'sdiscordprofile hides$XDG_RUNTIME_DIR/discord-ipc-0; add this to/etc/firejail/discord.local(the blacklists keep the keyring private):ignore include whitelist-runuser-common.inc blacklist ${RUNUSER}/keyring blacklist ${RUNUSER}/gcr -
The daemon itself must not run in a sandbox: it needs to see every process in
/proc.
Installation
Install discord-game-presence from the AUR, for example
with aurutils:
aur sync discord-game-presence
pacman -S discord-game-presence
The PKGBUILD builds the signed release tag, so import the signing key first:
gpg --recv-keys 7E12BC1FF3B6EDB2CD8053EB981A2B2A3BBF5514
Then enable the user service:
systemctl --user enable --now discord-game-presence
Logs go to the journal: journalctl --user -u discord-game-presence.
Usage
discord-game-presence [--config FILE] [--scan] [-v]
--scan: print the games running now and exit. Useful to check that a game is detected.--config FILE: config file (default~/.config/discord-game-presence/config.toml).-v,--verbose: debug logging.
Configuration
All settings are optional; see config.example.toml (installed in /usr/share/doc/discord-game-presence/).
interval: seconds between scans (default 5).linux_executables: also match Discord's Linux executable names (default false).ignore: games never to show, by Discord app ID or name. Use it for games that already report themselves to Discord (for example throughrpc-bridge), so they don't show twice.[executables]: extra executable names or path suffixes mapped to Discord app IDs, for games Discord's list doesn't match. These take priority over the list.
App IDs are in Discord's list, or in Discord's developer mode (right-click a game's activity, Copy ID).
After changing the config, restart the service.