Lachee / discord-rpc-csharp

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

SetPresence doesn't work #32

Closed 06Games closed 6 years ago

06Games commented 6 years ago

Hello, I don't know if I'm doing it wrong but I can't get the SetPresence function working on Unity 2017.1.3p3.

I only get this : 2018-07-22_17h18_01

Here is my code :

 public DiscordRpcClient client;

    void Initialize()
    {
        client = new DiscordRpcClient(TheClientID, null, true, -1, new DiscordRPC.IO.NativeNamedPipeClient()); //Create a discord client
        client.Logger = new ConsoleLogger() { Level = LogLevel.Warning }; //Set the logger

        //Subscribe to events
        client.OnPresenceUpdate += (sender, e) =>
        {
            Debug.LogFormat("Received Update! {0}", e.Presence);
        };

        client.Initialize(); //Connect to the RPC

        //Set the rich presence
        client.SetPresence(new RichPresence()
        {
            Details = "Example Project",
            State = "csharp example",
            Assets = new Assets()
            {
                LargeImageKey = "default"
            }
        });
    }

    void OnEnable()
    {
        DontDestroyOnLoad(gameObject);
        Initialize();
    }

    void Update()
    {
        client.Invoke(); //Invoke all the events, such as OnPresenceUpdate
    }

    void OnDisable()
    {
        client.Dispose();
    }
Lachee commented 6 years ago

Hello there,

Could you post some errors you are experiencing?

If you are using the ConsoleLogger within unity I should make mention that it won't display anything. That is using the stdout instead of the unity debugger. For a unity compatible logger, check out this gist I made: https://gist.github.com/Lachee/8e98934b4fd17094aea29d224e05418a

If you are getting "dll not found" once you implement the DebugLogger linked, try copying the DiscordRPC.Native.dll to the project root folder (outside assets, next to the solution file).

06Games commented 6 years ago

Hi, I correctly integrate your script into my project, and I got the error you described but copying the DiscordRPC.Native.dll file to the project root folder, didn't change anything. I always get these three errors : 2018-07-23_12h46_21

Do you have an idea ?

EDIT : I also tried to copy the dll to /assets/plugins/ as written in the issue #31. It didn't change anything.

06Games commented 6 years ago

I think the problem comes from the API and not from my instalation because the official api is working properly.

I will go back to the official Discord RPC api, waiting for a more stable version of this api, Thanks to @Lachee for taking the time to solve my first problem.