Lachee / discord-rpc-csharp

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

Buttons dont work #143

Closed DeathlyBower959 closed 3 years ago

DeathlyBower959 commented 3 years ago

I have my public void named initialize, with the stuff inside, but the buttons dont work

I expect a button to show up on the rich presence

Desktop (please complete the following information):

MY CODE All variables in here are defined, the main problem is with the new DiscordRPC.button thing and client.SetPresence

public void Initialize()
        {
                client = new DiscordRpcClient("832806990953840710");

                //Set the logger
                client.Logger = new ConsoleLogger() { Level = LogLevel.Warning };

                //Subscribe to events
                client.OnReady += (sender, e) =>
                {
                    Console.WriteLine("Received Ready from user {0}", e.User.Username);
                };

                client.OnPresenceUpdate += (sender, e) =>
                {
                    Console.WriteLine("Received Update! {0}", e.Presence);
                };

                Thread.Sleep(100);
                client.Initialize();

                //Set the rich presence
                //Call this as many times as you want and anywhere in your code.\
                new DiscordRPC.Button() { Label = "Test", Url = "https://test" };

                client.SetPresence(new RichPresence()
                {
                    Details = "Idling In Launcher...",
                    State = Properties.Ventile.Default.LineRPC,
                    Timestamps = new Timestamps()
                    {
                        Start = DateTime.UtcNow.AddSeconds(1)
                    },
                    Assets = new Assets()
                    {
                        LargeImageKey = "logo",
                        LargeImageText = Properties.Ventile.Default.Version,
                    }
                });
        }
Lachee commented 3 years ago

Framework: Im new, no clue

For "Framework", i wanted to know if this is a console application, in Unity3D, monogame etc etc. Basically what you are using to make this. If its a console application i need to know if you are using .NET Framework 4.7 or .NET Core 2 (that is determined when you are creating the project).

Version: Wot

This is the version of the nuget package you are using. Only applicable if you are using a non-unity framework.

The issue You dont actually set your rich presences to have any buttons. new DiscordRPC.Button() { Label = "Test", Url = "https://test" }; is creating the button, but you are immediately throwing it away by doing nothing with it.

You need to set the Buttons property in the RichPresence object you create when you go to SetPresence, as per The Example.

DeathlyBower959 commented 3 years ago

The example didn't work, there are 2 errors. I used the example and it just shows those errors, is there something im doing wrong?

'Button' is an ambiguous reference between 'DiscordRPC.Button' and 'System.Windows.Forms.Button'
'Button' is an ambiguous reference between 'DiscordRPC.Button' and 'System.Windows.Forms.Button'

MY NEW CODE

 public void Initialize()
        {
            if (Properties.Ventile.Default.RpcE == true) {
                client = new DiscordRpcClient("832806990953840710");

                Thread.Sleep(100);
                client.Initialize();

                //Set the rich presence
                //Call this as many times as you want and anywhere in your code.\

                client.SetPresence(new RichPresence()
                {
                    Details = "Idling In Launcher...",
                    State = Properties.Ventile.Default.LineRPC,
                    Timestamps = new Timestamps()
                    {
                        Start = DateTime.UtcNow.AddSeconds(1)
                    },
                    Assets = new Assets()
                    {
                        LargeImageKey = "logo",
                        LargeImageText = Properties.Ventile.Default.Version,
                    },
                    Buttons = new Button[]
                    {
                    new Button() { Label = "Fish", Url = "https://lachee.dev/" }
                    }
                });
            }
        }
DeathlyBower959 commented 3 years ago

Wait im sorry, I just got it, it needed to be DiscordRPC.Button instead of Button Im new to Visual Studio 2019, so im learning as I go, sorry to bother you.

Lachee commented 3 years ago

Im not sure why you have a Thread.Sleep, that isn't required

DeathlyBower959 commented 3 years ago

I have It there, because sometimes there are lag spikes, so I added a cooldown to enable disable rpm, and if I put delays around, it doesnt lag as much