discord-rpc-csharp icon indicating copy to clipboard operation
discord-rpc-csharp copied to clipboard

[BUG] RPC doesn't update a second time or beyond

Open Founntain opened this issue 4 years ago • 10 comments

Describe the bug After initializing the client and setting the RPC for the first time it works totally fine. Updating the presence doesn't work anymore. Worked perfectly fine before. Looking inside the OnPresenceUpdate the presence got updated, but the discord client doesn't show the updated RPC

To Reproduce Steps to reproduce the behavior:

  1. Create Client
  2. Initialize the client
  3. Set RPC once
  4. Set RPC again

Expected behavior The discord client should change the presence to the according data

Desktop (please complete the following information):

  • OS: Win 10
  • Framework: .NET Framework 4.6.1
  • DiscordRichPresence Version: 1.0.175

Additional context First RPC (correct)

Second presence (Not updated) Should be LA FESTA LA VITA by GUHROOVY

Data from OnPresenceUpdate Screenshot after successfull update

I also want to mention that it worked totally fine I just noticed it now. No code changes made. If I have to change something because of changes of the RPC, please let me know.

Founntain avatar May 28 '21 17:05 Founntain

I'll look into this and see if I can reproduce it. Are you able to provide a code snippet that reproduces this issue?

Lachee avatar May 29 '21 13:05 Lachee

Code Snipptes

Client.Invoke() isn't called manually by me because of AutomaticeInvoke is set to true (by default)

I hope these will help you. If you need anything please tell I try to give you as much info as I possible can.

private DiscordRpcClient Client;
private RichPresence Presence;

//Initializing the client
private void Initialize()
{
    Debug.WriteLine("Creating... Discord Client");

    Client = new DiscordRpcClient(ClientId)
    {
        Logger = new ConsoleLogger {Level = DiscordLogLevel}
    };

    Debug.WriteLine("Subscribing Discord events...");

    Client.OnReady += OnReady;
    Client.OnClose += OnClose;
    Client.OnError += OnError;

    Client.OnConnectionEstablished += OnConnectionEstablished;
    Client.OnConnectionFailed += OnConnectionFailed;

    Client.OnPresenceUpdate += OnPresenceUpdate;

    Client.OnSubscribe += OnSubscribe;
    Client.OnUnsubscribe += OnUnsubscribe;

    Client.OnJoin += OnJoin;
    Client.OnJoinRequested += OnJoinRequested;

    Client.SetSubscription(EventType.Join | EventType.JoinRequest);
    Client.Initialize();

    Debug.WriteLine("Discord Initialize finished...\n");
}

//Method to update the current Discord RPC
public void UpdatePresence(string details, string state, int partySize, string joinSecret)
{
    var presence = new RichPresence
    {
        Details = details,
        State = state,
        Assets = new Assets { },
        Party = new Party {ID = OsuPlayer.PartyManager.PartyId ?? string.Empty, Size = partySize, Max = 256}
    };

    presence.Secrets = new Secrets
    {
        JoinSecret = joinSecret
    };

    Client.SetPresence(presence);
}

Founntain avatar May 29 '21 15:05 Founntain

I am currently hitting this bug aswell, my code:

public class MainMod : MelonMod
    {
        public static DiscordRpcClient client;
        public static MelonLogger.Instance Logger;
        private float timer = 0.0f;
        public float period = 15f;

        public override void OnApplicationLateStart()
        {
            Logger = LoggerInstance;
        }

        public override void OnSceneWasLoaded(int buildIndex, string sceneName)
        {
            if (client == null)
            {
                client = new DiscordRpcClient("925431370577231974", client: new UnityNamedPipe())
                {
                    Logger = new LoggerPassthrough()
                };

                client.OnReady += (sender, e) =>
                {
                    LoggerInstance.Msg("Received Ready from user " + e.User.Username);
                    client.SetPresence(new RichPresence()
                    {
                        State = "Idle",
                        Assets = new DiscordRPC.Assets()
                        {
                            LargeImageKey = "big-image"
                        }
                    });
                };

                client.OnPresenceUpdate += (sender, e) =>
                {
                    LoggerInstance.Msg("Received Update! " + e.Presence);
                };

                client.Initialize();
            }
        }

        public override void OnUpdate()
        {
            timer += Time.deltaTime;

            if (timer > period)
            {
                timer = timer - period;
                LoggerInstance.Msg("Tick RPC");
                Logger.Msg(String.Format("{0}/15 | {1} | {2}", Hooks._big.CurrentRoom.RemoteUsers.Count, Hooks._big.CurrentRoom.Name, Hooks._big.CurrentRoom.Visibility));
                Logger.Msg(Hooks._big.CurrentRoom.Environment);
                client.ClearPresence();
                client.SetPresence(new RichPresence()
                {
                    State = String.Format("{0}/15 | {1} | {2}", Hooks._big.CurrentRoom.RemoteUsers.Count, Hooks._big.CurrentRoom.Name, Hooks._big.CurrentRoom.Visibility),
                    Details = Hooks._big.CurrentRoom.Environment,
                    Assets = new DiscordRPC.Assets()
                    {
                        LargeImageKey = "big-image"
                    }
                });
            }
        }

        public override void OnApplicationQuit()
        {
            client.Dispose();
        }
    }
        ```

IMB11 avatar Dec 28 '21 20:12 IMB11

Manually client.Invoke()ing doesn't do any difference.

IMB11 avatar Dec 28 '21 20:12 IMB11

@Founntain Did you get it fixed or?

IMB11 avatar Dec 28 '21 20:12 IMB11

Seems to be linked to #84

IMB11 avatar Dec 28 '21 20:12 IMB11

@Founntain Did you get it fixed or?

Well I can't tell. I really waited for an response to that. And I have to say sometimes it just keeps working fine and sometimes it doesn't have to check tho.

Founntain avatar Dec 29 '21 19:12 Founntain

Hmm, it seems I'll have to use the Discord Game SDK as this is broken and should be deprecated already anyways.

IMB11 avatar Dec 30 '21 10:12 IMB11

Is there any update on this? @Lachee

IMB11 avatar May 15 '22 14:05 IMB11

This library isn't broken or deprecated. The core library is working fine, if there is an issue its likely just the Unity package. If you are able to provide logs with the latest package, then please share them as they will be better able to diagnose the issue.

Lachee avatar May 18 '22 04:05 Lachee

Im using this for Unity via a modloader, specifically MelonLoader - I've imported UnityNamedPipe - there are no logs because it works as intended, just the presence doesn't change after 1 update

IMB11 avatar May 18 '22 18:05 IMB11