PYPRESENCE(1) pypresence PYPRESENCE(1) NAME pypresence - pypresence Documentation INSTALLATION Install pypresence with pip: For the last full release, you can use: pip install pypresence Or for the in-development release, you can use: pip install https://github.com/qwertyquerty/pypresence/archive/master.zip LINKS o Discord Support Server o Qwerty's Patreon (Some doll hairs would be nice) o pypresence GitHub Repository INFORMATION About Pypresence is a wrapper for Discord RPC. You can use it for Rich Presence for your games, as well as other discord integrations. Changelog 3.2.2 o Fixed support for 3.7 o Added nice end_in() method for Activities o Fixed some loopy looper mistakes 3.2.1 o FIXED A BUG THAT LITERALLY BROKE ANYTHING THAT WASN'T THE ACTIVITY CLASS o Began work on new docs 3.2.0 o Added async clients, AioClient() and AioPresence() o Added the useful tool of Activity() o New (internally used) Payload() class o Neko fixed some of qwerty's Y I K E S coding 3.1.1 o Fix support for 3.5 (again) o More small internal improvements 3.1.0 o Support for python 3.5 o Many small internal improvements 3.0.0 o Added Response object, which is now returned instead of dicts Quickstart +----------------------------------------+ |This page exists for if you have | |literally no clue what you're doing, or | |you just need a quick start. (For rich | |presence) | +----------------------------------------+ The first thing youll want to do is create a Discord RPC app. Here are the steps: o Navigate to https://discord.com/developers/ o Click "Create an Application." o Setup the application how you want, give it the name you want, and give it a good image. o Right under the name of your application, locate your Client ID. You will need this later. o Lastly, save your application. Next, you need to install pypresence. You will need python 3.5 - 3.7 installed. Here are the steps: o Open command prompt o Type pip3 install pypresence and hit enter o It should say something near the end that says something like "Successfully installed pypresence". Now you will need to create the program to set your rich presence. First we need to import what we need, like so: from pypresence import Presence # The simple rich presence client in pypresence import time Next we need to initialize our Rich Presence client. You'll need that Client ID from earlier: client_id = "ID HERE" # Put your Client ID in here RPC = Presence(client_id) # Initialize the Presence client Now we need to connect our Client to Discord, so it can send presence updates: RPC.connect() # Start the handshake loop Now we need to actually set our rich presence. We can use the update() function for this. There are many options we can use, but for this we will use state: RPC.update(state="Rich Presence using pypresence!") # Updates our presence Now we need our program to run forever, so we use a while loop. while True: # The presence will stay on as long as the program is running time.sleep(15) # Can only update rich presence every 15 seconds Now when you run your program, it should look something like this! [image: Finished Presence] [image] Examples Here is a list of examples using pypresence: Basic Rich Presence: from pypresence import Presence import time client_id = '64567352374564' # Fake ID, put your real one here RPC = Presence(client_id) # Initialize the client class RPC.connect() # Start the handshake loop print(RPC.update(state="Lookie Lookie", details="A test of qwertyquerty's Python Discord RPC wrapper, pypresence!")) # Set the presence while True: # The presence will stay on as long as the program is running time.sleep(15) # Can only update rich presence every 15 seconds Rich Presence to show CPU usage: import psutil from pypresence import Presence import time client_id = '64567352374564' # Fake ID, put your real one here RPC = Presence(client_id,pipe=0) # Initialize the client class RPC.connect() # Start the handshake loop while True: # The presence will stay on as long as the program is running cpu_per = round(psutil.cpu_percent(),1) # Get CPU Usage mem = psutil.virtual_memory() mem_per = round(psutil.virtual_memory().percent,1) print(RPC.update(details="RAM: "+str(mem_per)+"%", state="CPU: "+str(cpu_per)+"%")) # Set the presence time.sleep(15) # Can only update rich presence every 15 seconds Rich Presence to loop through quotes: from pypresence import Presence import time import random client_id = '64567352374564' # Put your Client ID here, this is a fake ID RPC = Presence(client_id) # Initialize the Presence class RPC.connect() # Start the handshake loop quotes = [ "If you can dream it, you can achieve it.", "Either write something worth reading or do something worth writing.", "You become what you believe.", "Fall seven times and stand up eight.", "The best revenge is massive success.", "Eighty percent of success is showing up.", "Life is what happens to you while you're busy making other plans.", "Strive not to be a success, but rather to be of value.", "The best time to plant a tree was 20 years ago. The second best time is now.", "Everything you've ever wanted is on the other side of fear." ] # The quotes to choose from while True: # The presence will stay on as long as the program is running RPC.update(details="Famous Quote:", state=random.choice(quotes)) #Set the presence, picking a random quote time.sleep(60) #Wait a wee bit Furthermore, the following is a list of repositories which use pypresence DOCUMENTATION Presence() class Presence(client_id, pipe=0, loop=None, handler=None) Creates the Presence client ready for usage. Parameters o client_id (str) -- OAuth2 App ID (found here) o pipe (int) -- Pipe that should be used to connect to the Discord client. Defaults to 0, can be 0-9 o loop (asyncio.BaseEventLoop) -- Your own event loop (if you have one) that PyPresence should use. One will be created if not supplied. Information at https://docs.python.org/3/library/asyncio-eventloop.html o handler (function) -- The exception handler pypresence should send asynchronous errors to. This can be a coroutine or standard function as long as it takes two arguments (exception, future). Exception will be the exception to handle and future will be an instance of asyncio.Future connect() Initializes the connection - must be done in order to make any updates to Rich Presence. Return type pypresence.Response clear(pid=os.getpid()) Clears the presence. Parameters pid (int) -- the process id of your game Return type pypresence.Response close() Closes the connection. Return type pypresence.Response update(**options) Sets the user's presence on Discord. Parameters o pid (int) -- the process id of your game o state (str) -- the user's current status o details (str) -- what the player is currently doing o start (int) -- epoch time for game start o end (int) -- epoch time for game end o large_image (str) -- name of the uploaded image for the large profile artwork o large_text (str) -- tooltip for the large image o small_image (str) -- name of the uploaded image for the small profile artwork o small_text (str) -- tootltip for the small image o party_id (str) -- id of the player's party, lobby, or group o party_size (list) -- current size of the player's party, lobby, or group, and the max in this format: [1,4] o join (str) -- unique hashed string for chat invitations and ask to join o spectate (str) -- unique hashed string for spectate button o match (str) -- unique hashed string for spectate and join o buttons (list) -- list of dicts for buttons on your profile in the format [{"label": "My Website", "url": "https://qtqt.cf"}, ...], can list up to two buttons o instance (bool) -- marks the match as a game session with a specific beginning and end Return type pypresence.Response Client() class Client(client_id, pipe=0, loop=None, handler=None) Creates the RPC client ready for usage. Parameters o client_id (str) -- OAuth2 App ID (found at https://discord.com/developers/applications/me) o pipe (int) -- Pipe that should be used to connect to the Discord client. Defaults to 0, can be 0-9 o loop (asyncio.BaseEventLoop) -- Your own event loop (if you have one) that PyPresence should use. One will be created if not supplied. Information at https://docs.python.org/3/library/asyncio-eventloop.html o handler (function) -- The exception handler pypresence should send asynchronous errors to. This can be a coroutine or standard function as long as it takes two arguments (exception, future). Exception will be the exception to handle and future will be an instance of asyncio.Future start() Initializes the connection - must be done in order to run RPC commands. Return type pypresence.Response close() Closes the connection. authorize(client_id, scopes, rpc_token=None, username=None) Used to authenticate a new client with your app. By default this pops up a modal in-app that asks the user to authorize access to your app. Parameters o client_id (str) -- OAuth2 application id o scopes (list) -- a list of OAuth scopes as strings o rpc_token (str) -- one-time use RPC token o username (str) -- username to create a guest account with if the user does not have Discord Return type pypresence.Response All the different scopes can be found here authenticate(token) Used to authenticate an existing client with your app. Parameters token (int) -- OAuth2 access token Return type pypresence.Response get_guilds() Used to get a list of guilds the client is in. Return type pypresence.Response get_channels() Used to get a guild's channels the client is in. Return type pypresence.Response channel_id() Used to get a channel the client is in. Parameters channel_id (str) -- id of the channel to get Return type pypresence.Response set_user_voice_settings(user_id, **options) Used to get a channel the client is in. Parameters o user_id (str) -- user id o pan_left (float) -- left pan of the user o pan_right (float) -- right pan of the user o volume (int) -- the volume of user (defaults to 100, min 0, max 200) o mute (bool) -- the mute state of the user Return type pypresence.Response select_voice_channel(channel_id) Used to join and leave voice channels, group dms, or dms. Parameters channel_id (str) -- channel id to join (or None to leave) Return type pypresence.Response get_selected_voice_channel() Used to get the client's current voice channel. Return type pypresence.Response select_text_channel(channel_id) Used to join and leave text channels, group dms, or dms. Parameters channel_id (str) -- channel id to join (or None to leave) Return type pypresence.Response set_activity(**options) Used to set the activity shown on Discord profiles and status of users. Takes the following as parameters. Parameters o pid (int) -- the process id of your game o state (str) -- the user's current status o details (str) -- what the player is currently doing o start (int) -- epoch time for game start o end (int) -- epoch time for game end o large_image (str) -- name of the uploaded image for the large profile artwork o large_text (str) -- tooltip for the large image o small_image (str) -- name of the uploaded image for the small profile artwork o small_text (str) -- tootltip for the small image o party_id (str) -- id of the player's party, lobby, or group o party_size (list) -- current size of the player's party, lobby, or group, and the max in this format: [1,4] o join (str) -- unique hashed string for chat invitations and ask to join o spectate (str) -- unique hashed string for spectate button o match (str) -- unique hashed string for spectate and join o buttons (list) -- list of dicts for buttons on your profile in the format [{"label": "My Website", "url": "https://qtqt.cf"}, ...], can list up to two buttons o instance (bool) -- marks the match as a game session with a specific beginning and end Return type pypresence.Response clear_activity(pid=os.getpid()) Clear the activity. Parameters o pid (int) -- the process id of your game o state (str) -- the user's current status o details (str) -- what the player is currently doing o start (int) -- epoch time for game start o end (int) -- epoch time for game end o large_image (str) -- name of the uploaded image for the large profile artwork o large_text (str) -- tooltip for the large image o small_image (str) -- name of the uploaded image for the small profile artwork o small_text (str) -- tootltip for the small image o party_id (str) -- id of the player's party, lobby, or group o party_size (list) -- current size of the player's party, lobby, or group, and the max in this format: [1,4] o join (str) -- unique hashed string for chat invitations and ask to join o spectate (str) -- unique hashed string for spectate button o match (str) -- unique hashed string for spectate and join o instance (bool) -- marks the match as a game session with a specific beginning and end Return type pypresence.Response subscribe(event, args={}) Used to subscribe to events. Parameters o event (str) -- event name to subscribe to o args (dict) -- any args to go along with the event Return type pypresence.Response unsubscribe(event, args={}) Used to unsubscribe from events. Parameters o event (str) -- event name to unsubscribe from o args (dict) -- any args to go along with the event Return type pypresence.Response get_voice_settings() Get the user's voice settings. Return type pypresence.Response set_voice_settings(**options) Set the user's voice settings. Parameters o _input (dict) -- input settings o output (dict) -- output settings o mode (dict) -- voice mode settings o automatic_gain_control (bool) -- state of automatic gain control o echo_cancellation (bool) -- state of echo cancellation o noise_suppression (bool) -- state of noise suppression o qos (bool) -- state of voice quality of service o silence_warning (bool) -- state of silence warning notice o deaf (bool) -- state of self-deafen o mute (bool) -- state of self-mute Return type pypresence.Response capture_shortcut(action) Used to capture a keyboard shortcut entered by the user. Parameters action (string) -- capture action, either 'START' or 'STOP' Return type pypresence.Response send_activity_join_invite(user_id) Used to accept an Ask to Join request. Parameters user_id (str) -- user id Return type pypresence.Response close_activity_request(user_id) Used to reject an Ask to Join request. Parameters user_id (str) -- user id Return type pypresence.Response register_event(event, func, args={}) Hook an event to a function. The function will be called whenever Discord sends that event. Will auto subscribe to it. Parameters o event (str) -- the event to hook o func (function) -- the function to pair with the event o args (dict) -- optional args used in subscription Return type pypresence.Response unregister_event(event, args={}) Unhook an event from a function. Will auto unsubscribe from the event as well. Parameters o event (str) -- the event to unhook o args (dict) -- optional args used in unsubscription Return type pypresence.Response AUTHOR qwertyquerty, LewdNeko COPYRIGHT 2024, qwertyquerty 3.2 July 13, 2024 PYPRESENCE(1)