C
C#2y ago
Lemur2591

❔ Need help Integrating Discord Rich Presence into a project (Visual Studio)

I'm hosting an empty program for now
static void UpdatePresence()
{
DiscordRichPresence discordPresence;
memset(&discordPresence, 0, sizeof(discordPresence));
discordPresence.state = "Roaming Orgrimmar";
discordPresence.details = "Ruby the Undead";
discordPresence.largeImageKey = "wotlk";
discordPresence.largeImageText = "WoW: Wrath of the Lich King";
discordPresence.smallImageKey = "rogue";
discordPresence.smallImageText = "Rogue - Level 6";
Discord_UpdatePresence(&discordPresence);
}
static void UpdatePresence()
{
DiscordRichPresence discordPresence;
memset(&discordPresence, 0, sizeof(discordPresence));
discordPresence.state = "Roaming Orgrimmar";
discordPresence.details = "Ruby the Undead";
discordPresence.largeImageKey = "wotlk";
discordPresence.largeImageText = "WoW: Wrath of the Lich King";
discordPresence.smallImageKey = "rogue";
discordPresence.smallImageText = "Rogue - Level 6";
Discord_UpdatePresence(&discordPresence);
}
is all the stuff I wanna show, but looking at my errors it seems as though either I've installed it wrong, or there's things I need to define and haven't
112 Replies
Lemur2591
Lemur2591OP2y ago
let me share my set up real quick
Relevant
Relevant2y ago
Is that a NuGet package or something?
Lemur2591
Lemur2591OP2y ago
Angius
Angius2y ago
Just FYI and for future reference, the fact you're using Visual Studio doesn't really matter
Lemur2591
Lemur2591OP2y ago
it's the discordGameSDK, I've moved everything from the C sharp folder to it's correct folder, and put the lib folders into plugins doesn't unity have certain functions that don't work in other programs and stuff?
Relevant
Relevant2y ago
I don't see a class for DiscordRichPresence in that list of files. Is that defined somewhere?
Angius
Angius2y ago
You can use Unity with Rider, VS Code, or even Notepad++ The IDE doesn't matter in the slightest
Lemur2591
Lemur2591OP2y ago
oh I presumed that was defined with the plugin or something
Lemur2591
Lemur2591OP2y ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
Lemur2591
Lemur2591OP2y ago
this is what I'm trying to follow
Relevant
Relevant2y ago
Could be. I know the plugins sub folders are collapsed, so it mightbe in there. That would just be the first thing I'd check. Is it actually defined anywhere I'll take a look at that link
Lemur2591
Lemur2591OP2y ago
oh, I'll try this, thanks oh hang on for the non-unity I just want the DLL in my solution just checking, does solution just refer to the entire project in it's decompiled form?
Relevant
Relevant2y ago
"Solution" in your case is anything within "ALPHA TEST C" oops sorry, that's your project, not solution It would be the level above that would be your solution Which is not shown in your screenshot
Angius
Angius2y ago
Solution is a collection of projects
Relevant
Relevant2y ago
Lemur2591
Lemur2591OP2y ago
man the learning curve is steep aye? hold on I'll do a couple google searches real quick and see if I can figure this out
Lemur2591
Lemur2591OP2y ago
oh wait so when it says put the dll next to the solution it's like this?
Lemur2591
Lemur2591OP2y ago
I think I did it right
Lemur2591
Lemur2591OP2y ago
Lemur2591
Lemur2591OP2y ago
now there's only one error and this one doesn't seem like an issue with the plugin, this seems like an issue with my code
Relevant
Relevant2y ago
I don't generally see SDKs set up like that. I usually see them in a separate project, but it looks like doing it that way worked 🙂
Lemur2591
Lemur2591OP2y ago
😄 and I found a tutorial that will hopefully iron out the error I got, and help me define my application ID, you can tell I'm gonna struggle to link my database to this when the time comes, let alone fetch and send data to it 😓
Relevant
Relevant2y ago
Do you know a any SQL?
Lemur2591
Lemur2591OP2y ago
not really, basically everything I've done except for html and css has been third party stuff
Angius
Angius2y ago
No need for SQL EF Core FTW
Relevant
Relevant2y ago
Connecting to a database isn't very complicated
Lemur2591
Lemur2591OP2y ago
oh
Relevant
Relevant2y ago
Someone else recommended not to use EF Core for a beginner. I'd agree more if the person already knew SQL, but if not, I could see the argument to be made either way
Lemur2591
Lemur2591OP2y ago
I'll trust you on this one, as you guys seem very helpful
Relevant
Relevant2y ago
It might also be a pain to set up EF Core since you aren't using dependency injection
Angius
Angius2y ago
Why would it be a pain? using var ctx = new DbContext() and let it rip
Relevant
Relevant2y ago
Not that DI makes it easier per se
Angius
Angius2y ago
Or... start using DI
Relevant
Relevant2y ago
I just figured if OP finds a tutorial that's using DI, but she isn't, could be confusing In any case, no matter the route you take, basic database transactions aren't anything scary
Lemur2591
Lemur2591OP2y ago
I hope so ahaha UI design seems easy, I know graphic design, I have a site, I have my servers, I have my databases so really the only thing I need is -discord integration (right around the corner) -database access (seems scary but you guys seem sure) -self updating ability (plenty of guides on that) -key injection (probably impossible; wouldn't worry about it) so things are moving smoothly
Pobiega
Pobiega2y ago
key injection
what exactly is this?
Lemur2591
Lemur2591OP2y ago
okay so basically one of the things on my database is called 'sessionkey' I don't know the ins and outs, all I know is that it is generated for security as a faster and more secure login the idea is that you can either enter your username and password, OR, the program can inject the sessionkey, and if it's valid then it skips the login the reason I say it's most likely impossible is because I don't know where it slots into with my executable
Angius
Angius2y ago
So... a remember-me cookie?
Lemur2591
Lemur2591OP2y ago
yeah I guess so but session based it's for world of warcraft the problem is that I have my own database and servers and everything, but as far as I'm concerned it's a blizzard secret how the key actually goes in it'd be funny if it's just a launch perameter but I don't think it's that simple, I think I'd need to decypt the wow exe to actually know where it goes, and I don't have the talent or expertise to know how to do that because as of now, I can't even figure out why my programs closing itself The program '[27500] ALPHA TEST C.exe' has exited with code 0 (0x0). as far as I know that means the process has finished and closed with no problems, but I don't want it to finish, I want it to stay open
Pobiega
Pobiega2y ago
oh, this is for a wow private server? with your own launcher?
Relevant
Relevant2y ago
Stay open and do what?
Lemur2591
Lemur2591OP2y ago
yeah, I'm working on a launcher for my wow server just stay open long enough for me to check if the discord rich presence is working
Relevant
Relevant2y ago
So there's some sort of listener I'm assuming?
Pobiega
Pobiega2y ago
I'm not 100%, but this might be violating discord TOS and thus our server rules.
Lemur2591
Lemur2591OP2y ago
oh no don't worry about that, the version I'm running is abandonware
Pobiega
Pobiega2y ago
a program ends when it reaches the end, you'll need to keep it alive somehow. I'd suggest using a .NET hosting instance for now, if this is a console app Im not sure blizzard sees it that way 😛
Relevant
Relevant2y ago
Is the idea to be listening for some command in discord?
Lemur2591
Lemur2591OP2y ago
nah hahaha don't worry bout that, I emailed them about it and everything, the version I run is like an alpha version of wow, which according to blizzard is a copy of the game they never intend to sell or host
Pobiega
Pobiega2y ago
nah its just DiscordRichPresence, aka the "is playing... game name" thing under a persons name
Relevant
Relevant2y ago
ah okay But the application wouldn't need to keep running for that, right? It could just issue the update then end?
Lemur2591
Lemur2591OP2y ago
that's what I was thinking too but the status isn't there
Relevant
Relevant2y ago
You could add a Console.ReadKey() at the end of your code to keep the console open. Or set a breakpoint at the beginning of the update method and F10 through to make sure not errors occurred
Pobiega
Pobiega2y ago
once your program ends, discord removes the game thingy it needs to keep going for DRP to work
Lemur2591
Lemur2591OP2y ago
what's the play if it's a non-console program?
Pobiega
Pobiega2y ago
then you dont have this issue, as a GUI app will stay alive
Lemur2591
Lemur2591OP2y ago
weird....
Relevant
Relevant2y ago
What kind of app did you create it as when you created the project in VS?
Lemur2591
Lemur2591OP2y ago
just a form
Relevant
Relevant2y ago
That's not a project type WinForms application?
Lemur2591
Lemur2591OP2y ago
ye the one that doesn't say (.net ) in it's name that one wouldn't let me use C# 8
Pobiega
Pobiega2y ago
you mean doesnt say ".NET framework"?
Relevant
Relevant2y ago
Relevant
Relevant2y ago
That one?
Pobiega
Pobiega2y ago
yeah, framework is old and bad do not use.
Lemur2591
Lemur2591OP2y ago
well it says it in the description, just not the name
Pobiega
Pobiega2y ago
the one Relevant showed is good
Lemur2591
Lemur2591OP2y ago
that one :)
Relevant
Relevant2y ago
Yeah, that should be set up for you to run and open whatever the default form is set to
Lemur2591
Lemur2591OP2y ago
it only started closing after I put in the discordcontroller hey what's the loop command thingo again?
Relevant
Relevant2y ago
I don't think a loop is going to solve your problem
Lemur2591
Lemur2591OP2y ago
I want it to reset before it hits the end of the file incase that's it
Relevant
Relevant2y ago
Where is your method being called? Like are you creating an instance of your class in Program.cs then calling the method?
Lemur2591
Lemur2591OP2y ago
honestly I don't even know anymore @_@ it's 6 am now and I still haven't gotten drpc working for my lich king mod
using Discord;
using System.Security.Cryptography.X509Certificates;

new Discord.Discord(1079515451232637019);

var activity = new Discord.Activity
{
State = "Roaming Orgrimmar",
Details = "Ruby the Undead",
Timestamps =
{
Start = 5,

},
Assets =
{
LargeImage = "wotlk", // Larger Image Asset Value
LargeText = "WoW: Wrath of the Lich King", // Large Image Tooltip
SmallImage = "rogue", // Small Image Asset Value
SmallText = "Level 6 Assassination Rogue", // Small Image Tooltip
},
Party =
{
Id = "foo partyID",
Size = {
CurrentSize = 1,
MaxSize = 4,
},
},
Secrets =
{
Match = "foo matchSecret",
Join = "foo joinSecret",
Spectate = "foo spectateSecret",
},
Instance = true,

};
using Discord;
using System.Security.Cryptography.X509Certificates;

new Discord.Discord(1079515451232637019);

var activity = new Discord.Activity
{
State = "Roaming Orgrimmar",
Details = "Ruby the Undead",
Timestamps =
{
Start = 5,

},
Assets =
{
LargeImage = "wotlk", // Larger Image Asset Value
LargeText = "WoW: Wrath of the Lich King", // Large Image Tooltip
SmallImage = "rogue", // Small Image Asset Value
SmallText = "Level 6 Assassination Rogue", // Small Image Tooltip
},
Party =
{
Id = "foo partyID",
Size = {
CurrentSize = 1,
MaxSize = 4,
},
},
Secrets =
{
Match = "foo matchSecret",
Join = "foo joinSecret",
Spectate = "foo spectateSecret",
},
Instance = true,

};
take a look at this and tell me if it's what you're refering to I never remember all the coding words like method and string and parameter and stuff, all I ever remember is syntax
Relevant
Relevant2y ago
All that's happening here is you're creating a variable named activity that doesn't appear to do anything
Lemur2591
Lemur2591OP2y ago
they're in the swirly brackets D:
Relevant
Relevant2y ago
And if this is your program.cs file and you removed the code that was there by default, then that's why your forms app isn't running 🙂
Lemur2591
Lemur2591OP2y ago
nah nah nah the program.cs is basically untouched
Relevant
Relevant2y ago
That's just setting the property values for the object
Pobiega
Pobiega2y ago
hm I'm trying to get it working, can't seem to
Lemur2591
Lemur2591OP2y ago
namespace ALPHA_TEST_C
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new MainForm());
Console.ReadKey();

}
}
}
namespace ALPHA_TEST_C
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new MainForm());
Console.ReadKey();

}
}
}
Pobiega
Pobiega2y ago
dont do Console.ReadKey() in a winforms apps :d
Relevant
Relevant2y ago
Yeah, that shouldn't be needed. I assumed it was a console app earlier
Lemur2591
Lemur2591OP2y ago
I forgor I put it in there he
Relevant
Relevant2y ago
That Application.Run should keep it running Where is this code?
Lemur2591
Lemur2591OP2y ago
discord controller I think I have an idea
Relevant
Relevant2y ago
Where is DiscordController being used?
Lemur2591
Lemur2591OP2y ago
honestly idk it's always trouble when I have to use someone elses library
Lemur2591
Lemur2591OP2y ago
Relevant
Relevant2y ago
Well this seems unrelated to the library. Code won't execute until you tell it to. If you have nothing that is using DiscordController, it won't do anything
Pobiega
Pobiega2y ago
Pobiega
Pobiega2y ago
got it working
Relevant
Relevant2y ago
Maybe what you're wanting is to put a button or something in MainForm, then on button click, create an instance of the class, then call whatever method you want
Lemur2591
Lemur2591OP2y ago
oh what the heck, nice did you add something that actually uses the variable
Pobiega
Pobiega2y ago
I tried two different things with the official SDK, couldnt get it to work but there is an up to date alternative
Pobiega
Pobiega2y ago
DiscordRichPresence 1.1.3.18
A .NET implementation of Discord's Rich Presence functionality. This library supports all features of the Rich Presence that the official C++ library supports, plus a few extra. "Players love to show off what they are playing with Discord’s status feature. With Rich Presence you can add beautiful art and detailed information to show off your ga...
Pobiega
Pobiega2y ago
public static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder()
.Build();

var client = new DiscordRpcClient(DISCORD_ID);

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

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

client.SetPresence(new RichPresence()
{
Details = "Example Project",
State = "csharp example",
});

await host.RunAsync();
}
public static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder()
.Build();

var client = new DiscordRpcClient(DISCORD_ID);

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

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

client.SetPresence(new RichPresence()
{
Details = "Example Project",
State = "csharp example",
});

await host.RunAsync();
}
this is for a console app btw and Im using a host to stay alive so skip those parts if you want this for a winforms app but the center part, aka the stuff that deals with client works fine
Lemur2591
Lemur2591OP2y ago
wish me luck hahaha, my brain is mush rn, it's 6:30 am no sleep and I'll be amazed if I can get it installed right this code is way tider though :o thanks
Pobiega
Pobiega2y ago
just be aware, this might not be trivial to set up working nicely in a winforms app. I wouldn't want this in a form, but rather in the app itself.. but a form event (logging in) will be what triggers some of the SetPrecense calls I suppose you could expose the client instance via a static wrapper
Lemur2591
Lemur2591OP2y ago
can't I manually trigger a SetPresence call elsewhere?
Pobiega
Pobiega2y ago
thats fine for something like this.
Lemur2591
Lemur2591OP2y ago
I plan to set presence after every relevant database change
Relevant
Relevant2y ago
public partial class Form1 : Form
{
private DiscordRpcClient _client;
public Form1()
{
InitializeComponent();
InitializeClient();
}

private void button1_Click(object sender, EventArgs e)
{
_client.SetPresence(new RichPresence()
{
Details = "Example Project",
State = "csharp example",
});
}

private void InitializeClient()
{
_client = new DiscordRpcClient(DISCORD_ID);

_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); };

//Connect to the RPC
_client.Initialize();
}
}
public partial class Form1 : Form
{
private DiscordRpcClient _client;
public Form1()
{
InitializeComponent();
InitializeClient();
}

private void button1_Click(object sender, EventArgs e)
{
_client.SetPresence(new RichPresence()
{
Details = "Example Project",
State = "csharp example",
});
}

private void InitializeClient()
{
_client = new DiscordRpcClient(DISCORD_ID);

_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); };

//Connect to the RPC
_client.Initialize();
}
}
I haven't test this, but playing around putting that code into a form
Pobiega
Pobiega2y ago
this thing is an RPC client, it needs to stay alive, and you'll need to invoke updates and stuff there is a message pump involved. I would strongly refrain from doing exactly as above - a form instance owning the client imho a static wrapper will be better you could expose a helper method that provides easy access to the SetPresence call.
Lemur2591
Lemur2591OP2y ago
oh that seems easy enough :) I say as I can't figure out how to install the damn thing, and all words blur together into an incohent mess
Pobiega
Pobiega2y ago
so to summarize, I'd create my own non-static class that wraps this, then expose a single instance of that using a static singleton go sleep then no point coding when exhausted, it just turns out bad and no learning is done 😄
Lemur2591
Lemur2591OP2y ago
yeah, but I don't feel productive enough 😢
Pobiega
Pobiega2y ago
you wont get more productive as your sanity dwindles :p sleep, come back at it well rested and you'll get much further
Lemur2591
Lemur2591OP2y ago
okay 😔 Okay update, i've copied what other people have done down to the very letter, still not working, I'm starting to wonder if it's something wrong with my discord developer portal @Pobiega can I see your Oauth for the discord application you were testing? I worry I got something wrong
Pobiega
Pobiega2y ago
I did no OAuth, I posted literally all the code Except my discord ID
Lemur2591
Lemur2591OP2y ago
yeah no matter what I do it tells me there's stuff that doesn't exist in this context I've tried the nuget plugins DiscordRPC DiscordGameSDK and discord rich presence I think I'm just cursed or something, there's been way too many instances of things other people do fine that completely explode when I do the exact same thing
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server