Lachee / discord-rpc-csharp

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

[BUG] The rich presence dont show up #230

Closed Kiriox94 closed 1 year ago

Kiriox94 commented 1 year ago

Describe the bug I took the example present in the read me and I tried to include it in a simple form app to see what I could do afterwards except that when I click on my button it puts my name user but after I do not have the rich presence that appears

Desktop:

Additional context Edit: After some research I realized that my code was not good so I modified everything so that the rich presence is activated when the application is launched and not when I press the button My code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DiscordRPC;
using DiscordRPC.Logging;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public DiscordRpcClient client;

        public Form1()
        {
            InitializeComponent();

            client = new DiscordRpcClient("1082567452711469076");

            //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.Name);
            };

            //Connect to the RPC
            client.Initialize();
            client.SetPresence(new RichPresence()
            {
                Details = "Example Project",
                State = "csharp example",
                Assets = new Assets()
                {
                    LargeImageKey = "goose",
                    LargeImageText = "Lachee's Discord IPC Library"
                }
            });
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Set the rich presence

        }
    }
}

Logs

Received Ready from user Kiriox
Received Update! DiscordRPC.RichPresence
Le thread 0x6174 s'est arrêté avec le code 0 (0x0).