Closed decries closed 3 years ago
The error perfectly tells you what's wrong.
Buttons is an array, you are trying to assign a single object instead tho
I don't understand that explanation, i just need a wait to fix it, lol.
nvm, fixed lol
how was this fixed? I am having the same problem, and are new to c#
I have the same problem, ... NotLikeThis
Buttons are an array. use an array of buttons.
If you do not know how arrays work, here is a Brackeys Tutorial for C# beginners.
@DeathlyBower959 I found one solution...
DiscordRPC.Button[] btn = new DiscordRPC.Button[1];
private void Discord(){
client = new DiscordRpcClient(APPLICATION ID, -1);
client.Initialize();
string url = "https://google.com";
string Botaria = "Botaria";
btn[0] = JsonConvert.DeserializeObject<DiscordRPC.Button>("{\"Url\":\"" + url + "\", \"Label\":\"" + Botaria + "\"}");
string temp = "";
var rp = new RichPresence()
{
Details = "",
State = "",
Assets = new Assets()
{
SmallImageKey = "",
LargeImageKey = "",
},
Buttons = btn,
};
rp.Timestamps = new Timestamps(start);
client.SetPresence(rp);
}
that is.... one way to do it. However a better, cleaner way (that doesn't rely on JSON serialization (seriously dont do that just create the object)) would be the example provided https://github.com/Lachee/discord-rpc-csharp/blob/master/DiscordRPC.Example/Program.cs#L108-L111
new RichPresence()
{
Details = "A Basic Example",
State = "In Game",
Timestamps = Timestamps.FromTimeSpan(10),
Buttons = new Button[]
{
new Button() { Label = "Fish", Url = "https://lachee.dev/" }
}
}
Yeah, I figured that out a while ago, there is no reason to use JSON serialization, there is no point. Lachee's solution is much better, that's what I had originally used, and I'm a little more accustomed to c# now.
I implemented this:
` DiscordRPC.client.SetPresence(new RichPresence() {
And im getting this error: Cannot implicitly convert type 'DiscordRPC.Button' to 'DiscordRPC.Button[]'