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

[BUG] client.ClearPresence(); dont work

Open UrbanSide opened this issue 2 years ago • 4 comments

Describe the bug A clear and concise description of what the bug is. This code dont work,activity continues to hang for about a minute

                client.SetPresence(null);
                client.ClearPresence();

UrbanSide avatar Feb 19 '23 20:02 UrbanSide

I am also having the same issue

RegorForgot avatar Dec 06 '23 19:12 RegorForgot

I am also having the same issue

Forget it, the ticket has been open for almost a year now. Look for another library.

UrbanSide avatar Dec 06 '23 19:12 UrbanSide

wow rude, dont tell people to use other libraries within the help of this one.

Your issue is invalid anyways, please follow the issue templates next time. Dont know the bug, or what you are expecting. "This code dont work" is not very descriptive. I am unable to reproduce this issue, so any help you can provide is more than welcomed.

I will help however, to get this finally ticked away.

  • Starters, doing both SetPresence and ClearPresence here is redundant, as they both set it to null.
  • ClearPresence works on my end, please provide code to replicate your issue.
  • Ensure you are not later setting the presence elsewhere.
  • Enable the logs and share them here so i can validate the code is actually sending the clear

Lachee avatar Dec 08 '23 04:12 Lachee

I am unable to reproduce this issue, so any help you can provide is more than welcomed.

Hi, sorry as I just saw these comments now 10 months later. If it is worth anything, I had kept using this library since I think it is quite a good one. The way that this bug had occured is the following:

  1. Load a rich presence using this package
  2. Start another rich presence (for example Spotify)
  3. Deactivate the rich presence from this package
  4. Deactivate the other rich rpesence
  5. The rich presence from this package will "ghost" and keep staying on.

It's an edge case, definitely but some use cases, such as mine, had it more often.

In any case, I had also found that this wasn't even local to the rich presences from this package only! Even other rich presences, during the time, had ghosting issues. I think since the time that Discord had updated their rich presences, this issue has mostly subsided and I haven't noticed it happening with any presence (including attempting to force it).

RegorForgot avatar Oct 26 '24 06:10 RegorForgot

The problem definitely exists, the fix for me was is I had to make a little delay after calling ClearPresence and Dispose.

protected override void OnClosing(WindowClosingEventArgs e)
    {
        rpcClient.ClearPresence();
        rpcClient.Dispose();
        Task.Delay(200).Wait(); // Fixes the issue with Discord RPC not closing properly
        base.OnClosing(e);
    }

TavstalDev avatar Aug 19 '25 09:08 TavstalDev

The problem definitely exists, the fix for me was is I had to make a little delay after calling ClearPresence and Dispose.

protected override void OnClosing(WindowClosingEventArgs e) { rpcClient.ClearPresence(); rpcClient.Dispose(); Task.Delay(200).Wait(); // Fixes the issue with Discord RPC not closing properly base.OnClosing(e); }

Thanks, Ill see if I can reproduce this

Lachee avatar Aug 20 '25 05:08 Lachee

If you launch the app via its executable instead running it from the IDE, then the presence will be cleared when closing the application, but when you try to clear the presence during runtime it will not be cleared. For example using a button for clearing the presence will not actually clear the presence, until the application is closed.

Detailed steps to reproduce the issue: 0. Create an Avalonia Desktop Application.

  1. Add DiscordRichPresence (1.6.1.70) through nuget
  2. Add the following code to MainWindow.axaml.cs
private DiscordRpcClient rpcClient;

protected override void OnOpened(EventArgs e)
    {
        base.OnOpened(e);
        rpcClient = new DiscordRpcClient("your-client-id-here");
        rpcClient.Initialize();

        rpcClient.SetPresence(new RichPresence
        {
            Details = "Testing....",
            Timestamps = Timestamps.Now,
            Assets = new Assets
            {
                LargeImageKey = "logo",
                LargeImageText = "Test App",
            }
        });
    }

    protected override void OnClosing(WindowClosingEventArgs e)
    {
        rpcClient.ClearPresence();
        rpcClient.Dispose();
        base.OnClosing(e);
    }
  1. Launch the app and check discord.
  2. Close the app
  3. The presence did not get cleared.

Extra Information:

  • OS: Arch Linux
  • IDE: JetBrains Rider
  • Discord Client: Vesktop
  • The Task.Delay(200).Wait() stopped working since I posted my previous message. Setting it higher does not help.

TavstalDev avatar Aug 22 '25 12:08 TavstalDev