Here's the codeblock in my script.rpy file:
Code: Select all
# Discord Rich Presence
default persistent.presenceActive = True
init -20 python:
import discord_rpc
import time
start = time.time()
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
))
def connectDiscord():
if persistent.presenceActive:
callbacks = {
'ready': readyCallback,
'disconnected': disconnectedCallback,
'error': errorCallback,
}
discord_rpc.initialize('123456789101213141', callbacks=callbacks, log=False)
discord_rpc.update_connection()
discord_rpc.run_callbacks()
discord_rpc.update_presence(
**{
'details': 'Main Hall',
'start_timestamp': start,
'large_image_key': 'appicon'
}
)
discord_rpc.update_connection()
discord_rpc.run_callbacks()
else:
discord_rpc.shutdown()
Code: Select all
label before_main_menu:
$ connectDiscord()
return
Code: Select all
label splashscreen:
$ connectDiscord()
return
Code: Select all
vbox:
style_prefix "radio"
label _("Discord Presence")
textbutton _("Enable") action SetVariable("persistent.presenceActive", True), Function(connectDiscord)
textbutton _("Disable") action SetVariable("persistent.presenceActive", False), Function(discord_rpc.shutdown)