{"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pypresence"],"cli":null},"imports":["from pypresence import Presence","from pypresence import AioPresence","from pypresence.exceptions import InvalidID","from pypresence.exceptions import PipeError"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}