{"id":10124,"library":"pypresence","title":"PyPresence Discord RPC Client","description":"PyPresence is a Discord RPC client library for Python, enabling developers to integrate their applications with Discord's Rich Presence feature. It supports both synchronous and asynchronous operations for updating a user's status. The current version is 4.6.1, and it typically has releases for bug fixes and new Discord RPC features.","status":"active","version":"4.6.1","language":"en","source_language":"en","source_url":"https://github.com/qwertyquerty/pypresence","tags":["discord","rpc","presence","async","synchronous"],"install":[{"cmd":"pip install pypresence","lang":"bash","label":"Install stable release"}],"dependencies":[],"imports":[{"note":"For synchronous Discord Rich Presence updates.","symbol":"Presence","correct":"from pypresence import Presence"},{"note":"For asynchronous Discord Rich Presence updates, typically used with asyncio.","symbol":"AioPresence","correct":"from pypresence import AioPresence"},{"note":"Exception raised when an invalid Discord Application ID is used.","symbol":"InvalidID","correct":"from pypresence.exceptions import InvalidID"},{"note":"Exception raised when unable to connect to Discord IPC pipe.","symbol":"PipeError","correct":"from pypresence.exceptions import PipeError"}],"quickstart":{"code":"import time\nimport os\nfrom pypresence import Presence\n\n# Get CLIENT_ID from environment or set a placeholder\n# Replace with your actual Discord Application ID\nCLIENT_ID = os.environ.get('PYPRESENCE_CLIENT_ID', '123456789012345678') \n\n# Ensure Discord client is running before attempting to connect\n# Presence requires an integer ID, so convert if necessary.\nprint(f\"Attempting to connect with Client ID: {CLIENT_ID}\")\nRPC = Presence(CLIENT_ID)\n\ntry:\n    RPC.connect()\n    print(\"Connected to Discord RPC\")\n    \n    RPC.update(state=\"Playing a game!\", \n               details=\"Currently in a match\", \n               start=int(time.time()),\n               large_image=\"your_large_image_key\", \n               large_text=\"Large Image Text\",\n               small_image=\"your_small_image_key\", \n               small_text=\"Small Image Text\",\n               buttons=[{\"label\": \"Join My Game\", \"url\": \"https://example.com/join\"}])\n    \n    print(\"Presence updated. Will stay active for 30 seconds...\")\n    time.sleep(30) # Keep presence active for 30 seconds\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure Discord is running and your Client ID is correct.\")\nfinally:\n    RPC.close()\n    print(\"Disconnected from Discord RPC.\")","lang":"python","description":"This quickstart demonstrates how to use `pypresence.Presence` for synchronous Rich Presence updates. It connects to Discord, sets a custom presence with details, timestamps, images, and buttons, then maintains it for 30 seconds before disconnecting. Remember to replace `123456789012345678` with your actual Discord Application ID in production, or set the `PYPRESENCE_CLIENT_ID` environment variable."},"warnings":[{"fix":"Ensure the official Discord desktop client is running on your system before running your PyPresence application.","message":"Discord client must be running. PyPresence connects to Discord via an IPC (Inter-Process Communication) pipe. If the Discord desktop client is not running, PyPresence will fail to connect and raise a `PipeError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify your Client ID in the Discord Developer Portal (Applications -> Your App -> General Information). Ensure the 'Public' toggle is enabled if you want others to see your presence.","message":"Incorrect Client ID or application not public. Your Discord Application ID must be correct and belong to an application you own or have access to. For Rich Presence to be visible to others, the application's 'Public' toggle must be enabled in the Discord Developer Portal.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to pypresence v4.5.2 or newer to benefit from improved IPC pipe detection and connection/disconnection stability. This addresses issues like `get_ipc_path()` when `pipe=0` and broken pipe detection, which were hotfixed in v4.5.2.","message":"Changes in IPC pipe detection and closing logic in v4.5.x. Earlier versions might have had issues with reliable connection or proper closing, especially on Windows, leading to 'Pipe Not Found' errors or resources not being released.","severity":"breaking","affected_versions":"Prior to v4.5.2"},{"fix":"For synchronous applications, use `pypresence.Presence`. For asynchronous applications (e.g., with `discord.py` or `asyncio`), use `pypresence.AioPresence` and ensure your code is `await`ed appropriately within an event loop.","message":"Using `Presence` (sync) in an async context or `AioPresence` (async) in a sync context. While `Presence` is synchronous, `AioPresence` requires an `asyncio` event loop. Mixing them incorrectly can lead to `RuntimeError: Event loop is already running` or `RuntimeError: no current event loop`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Start the Discord desktop client application. If it's already running, try restarting your Python script or Discord. Ensure you have the latest pypresence version for improved pipe detection.","cause":"The Discord desktop client is not running, or pypresence cannot locate the IPC pipe.","error":"pypresence.exceptions.PipeError: Could not find Discord IPC pipe!"},{"fix":"Double-check your `CLIENT_ID` in the Discord Developer Portal (https://discord.com/developers/applications). Copy it directly and ensure it's passed as a string or integer.","cause":"The Discord Application ID provided to `Presence()` or `AioPresence()` is not a valid 18-19 digit number, or doesn't correspond to an existing Discord application.","error":"pypresence.exceptions.InvalidID: The Client ID you provided is invalid."},{"fix":"Ensure your `CLIENT_ID` is converted to an integer: `Presence(int(CLIENT_ID))` or `AioPresence(int(CLIENT_ID))`. While newer versions might handle string conversion, explicitly converting is safer.","cause":"The `CLIENT_ID` was passed as a string where an integer was expected, particularly in older versions or specific parts of the library's internal workings.","error":"TypeError: 'str' object cannot be interpreted as an integer"},{"fix":"Refer to the pypresence documentation or Discord Rich Presence API for valid keys and their expected types. Common keys include `state`, `details`, `start`, `end`, `large_image`, `large_text`, `small_image`, `small_text`, `buttons`, etc.","cause":"An invalid key was passed to the `update()` method, or the data structure for presence is incorrect according to Discord's API.","error":"KeyError: 'details'"}]}