Discord Rich Presence Issue

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Wiceramond
Regular
Posts: 25
Joined: Mon Dec 07, 2020 8:40 am
Contact:

Discord Rich Presence Issue

#1 Post by Wiceramond »

This is working but there is a weird issue I'm facing.

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()
And when I use the function connectDiscord() here:

Code: Select all

label before_main_menu:
    $ connectDiscord()
    return
It doesn't work, nothing works unless I call connectDiscord() twice but calling it in the same place don't work too. Let's say if I want to enable it in main menu, I need to call it in label splashscreen too.

Code: Select all

label splashscreen:
    $ connectDiscord()
    return
When I try to turn it on and off, turning it off works just fine but if I try Enable it, I have to click on enable twice too.

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)
Why is this happening? How can I solve this issue. Thanks in advance.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]