def setup(): client = Client(client_id) client.start() auth = client.authorize(client_id, ['rpc']) client.close() rpcToken = auth["data"]["code"] if rpcToken != None: headers = { "rpcToken": rpcToken, } user_object = requests.get("https://rich-presence-api.glitch.me/setup", headers=headers) if user_object.status_code == 200: user_json = user_object.json() with open(os.path.abspath(os.getcwd()) + '\data.json', 'w') as outfile: json.dump(user_json, outfile) return user_json else: raise RuntimeWarning("One or more of the apis errored.") else: raise RuntimeWarning("Error when obtaining RPC token.")
try: # Import modules from pypresence import Presence, Client import time # Connect to Discord cid = 706083923431522316 auth = "nV7OxD2xpWnolSxsm9VkGYcmy5re5V" rpc = Presence(cid) client = Client(cid, pipe=0) client.start() client.authorize(cid, ["rpc", "rpc.notifications.read"]) #client.authenticate(auth) print(client.get_selected_voice_channel()) #client.authorize(cid) rpc.connect() rpc.update(state="Rich Presence using pypresence!") #client.set_user_voice_settings(cid) print('RPC set successfully.') # Update RPC every 15 seconds while True: time.sleep(15) # Custom KeyboardInterrupt message except KeyboardInterrupt: print('\nProgram stopped using Ctrl+C.')