Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Founntain opened this issue May 28, 2021 · 10 comments
Open

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

Founntain opened this issue May 28, 2021 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@Founntain
Copy link

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 Founntain added the bug Something isn't working label May 28, 2021
@Lachee Lachee self-assigned this May 29, 2021
@Lachee
Copy link
Owner

Lachee commented May 29, 2021

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

@Founntain
Copy link
Author

Founntain commented May 29, 2021

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);
}

@IMB11
Copy link

IMB11 commented Dec 28, 2021

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
Copy link

IMB11 commented Dec 28, 2021

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

@IMB11
Copy link

IMB11 commented Dec 28, 2021

@Founntain Did you get it fixed or?

@IMB11
Copy link

IMB11 commented Dec 28, 2021

Seems to be linked to #84

@Founntain
Copy link
Author

@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.

@IMB11
Copy link

IMB11 commented May 15, 2022

Is there any update on this? @Lachee

@Lachee
Copy link
Owner

Lachee commented May 18, 2022

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.

@IMB11
Copy link

IMB11 commented May 18, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants