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