Lachee / discord-rpc-csharp

C# custom implementation for Discord Rich Presence. Not deprecated and still available!
MIT License
560 stars 93 forks source link

initialized but not showing??? #193

Closed kayner-dev closed 2 years ago

kayner-dev commented 2 years ago

ive checked my id and everything, but it fails to show up, and when I tried to deinitialize my rpc, it says my rpc wasn't initialized???

Lachee commented 2 years ago

Hi,

If you want help please follow the issue template, providing logs and your code.

I assume you are calling Initialize but cannot tell because you have bit provided enough information

kayner-dev commented 2 years ago

honestly, if i knew how to find log files, i think they would help me out too, anyway, what i am trying to do here is that everytime a checkbox is checked, discord rpc is supposed to initialize, i tried a lot of things, like using too excessive code

im using windows 10, and net 5.0 wpf

var Client = new DiscordRpcClient("620342495548669982", autoEvents: false);
            Client.Initialize();
            if (DiscordRPCCheckbox.IsChecked == true)
            {
                Client.Logger = new ConsoleLogger() { Level = LogLevel.Warning };
                var r = new RichPresence()
                {
                    Details = "Made by z_Kenneth#3492",
                    State = "In Main Menu",
                    Timestamps = Timestamps.FromTimeSpan(10),
                    Assets = new Assets()
                    {
                        LargeImageKey = "a",
                        LargeImageText = "a",
                    }
                };
                Client.SetPresence(r);
                Client.Dispose();
                lineChanger("DiscordRPC = true", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Falcon XXII\\Properties\\Settings.txt", 7);
            }
            else
            {
                lineChanger("DiscordRPC = false", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Falcon XXII\\Properties\\Settings.txt", 7);
                Client.ClearPresence();
                Client.Deinitialize();
            }
Lachee commented 2 years ago

You're disposing the client after you immediately set the presence. This will cause it to clean itself up and undo your presence. The client must be connected throughout the lifetime of your application. This is a limitation of both Discord (only showing presence of running apps) and Unity3D (DiscordRpcClient will send a CLEAR when it disposes to avoid the Unity Editor hanging).

I recommend treating the DiscordRpcClient like a singleton, have it a static in your main class and when you click the button then initialize / Deinitialize (these do not dispose the client). When your application exits, then dispose of client.

Logging solution can be configured like the README shows with client.Logger. By default, the library includes a ConsoleLogger, FileLogger and NullLogger. The FileLogger maybe useful if you dont have a console window.

kayner-dev commented 2 years ago

oh shit thanks! makes my life a lot easier without worrying about the client after deinitalization