Closed ghost closed 6 years ago
Hello, been meaning to respond to your other issue but glad you have managed to get started. Make sure you have the required dependencies in your project. The only dependency this library has is Newtonsoft.Json which you can install through the nuget package manager.
@Lachee Thank you for answering! I am installing Newtonsoft.Json now. I have a question. What is the DiscordPipe? I just put a random number there (1).
Update: I installed Newtonsoft but still get a error
Unmanaged exception: System.IO.FileNotFoundException: Unable to load file or composition Discord RPC, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null, or one of its dependencies. The file can not be found. at DiscordRPCTest.Program.Main (String [] args)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DiscordRPC;
using Newtonsoft;
namespace DiscordRPCTest
{
class Program
{
public static DiscordRpcClient client;
static void Main(string[] args)
{
client = new DiscordRpcClient("458202823641792512", true, 1);
//Subscribe to events
client.OnPresenceUpdate += (sender, e) =>
{
Console.WriteLine("Received Update! {0}", e.Presence);
};
//Connect to the RPC
client.Initialize();
//Set the rich presence
client.SetPresence(new RichPresence()
{
Details = "CrunchyHub",
State = "csharp example",
Assets = new Assets()
{
LargeImageKey = "image_large",
LargeImageText = "Lachee's Discord IPC Library",
SmallImageKey = "image_small"
}
});
Console.ReadLine();
}
}
}
Discord Pipe is the pipe number that discord is currently hosted on. It can be 0 to 9. Setting it to -1 will let the library to automatically scan for discord through those pipes.
What version of .NET are you working with? Are you using .NET Standard or a older version?
I think I found the solution hopefully. So in Visual Studio when you add the assembly, you need to make the library "Copy to Local". It should look similar to the following image:
.Net Framework 4.6.1 and yes, i have copy local enabled but it still doesn't work
And i dont have it as a assembly i have it as a reference. It's a console application
Made a github repo https://github.com/Hampusm/DiscordRPC-Csharp-test
@Lachee
@Hampusm found the problem. Your filename is DiscordRPC.dll
, however when you build DiscordRPC it outputs Discord RPC.dll
.NET expects the filename to be the same as the assembly name, but with .dll appended to the end. Since you renamed it (or bad build), it could not locate the correct file.
You can fix this by simply renaming your DiscordRPC.dll
to Discord RPC.dll
.
I have also just made made a commit which changes the assembly name from Discord RPC.dll
to DiscordRPC.dll
since it makes more sense, so I recommend you rebuild the library and replace our previous .dll with the new one.
Just to let you know. Dont close the issue yet i dont know it it works yet. i am cloning rn
Just updated my comment to be a bit clearer about the issue.
Got it to work now! Thank you @Lachee for the help!
Never mind it doesnt work. No error or anything discord just doesnt say anything
@Lachee
Nvm it works
Unmanaged exception: System.IO.FileNotFoundException: Unable to load file or composition Discord RPC, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null, or one of its dependencies. The file can not be found. at DiscordRPCTest.Program.Main (String [] args)