Last active
July 10, 2023 00:58
-
-
Save dooderstem/7b04738ab301aec10e243628a88d45ab to your computer and use it in GitHub Desktop.
discord_rpc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://pypi.org/project/discord-rpc.py/ | |
# pip install discord-rpc.py | |
import discord_rpc | |
import time | |
if __name__ == '__main__': | |
def readyCallback(current_user): | |
print('Our user: {}'.format(current_user)) | |
def disconnectedCallback(codeno, codemsg): | |
print('Disconnected from Discord rich presence RPC. Code {}: {}'.format( | |
codeno, codemsg | |
)) | |
def errorCallback(errno, errmsg): | |
print('An error occurred! Error {}: {}'.format( | |
errno, errmsg | |
)) | |
# Note: 'event_name': callback | |
callbacks = { | |
'ready': readyCallback, | |
'disconnected': disconnectedCallback, | |
'error': errorCallback, | |
} | |
discord_rpc.initialize('token', callbacks=callbacks, log=False) | |
i = 0 | |
start = time.time() | |
while i < 10: | |
i += 1 | |
discord_rpc.update_presence( | |
**{ | |
'details': 'Iteration # {}'.format(i), | |
'start_timestamp': start, | |
'large_image_key': 'default' | |
} | |
) | |
discord_rpc.update_connection() | |
time.sleep(2) | |
discord_rpc.run_callbacks() | |
discord_rpc.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment