Help with DiscordGameSDK in a C# project (no Unity)

I am currently trying to develop a plugin for a Unity game. For this I created a C# project, where I want to use Discord Rich Presence. Here is my main cs file:
using System.Collections;
using System.Collections.Generic;

public class Main : TheGameScript
{
private const ulong CLIENT_ID = 1234567890;
public Discord discord;

public override void Init()
{
var discord = new Discord(CLIENT_ID, (UInt64)Discord.CreateFlags.Default);
var activityManager = discord.GetActivityManager();
var activity = new Discord.Activity
{
State = "Still Testing",
Details = "Bigger Test"
};
activityManager.UpdateActivity(activity, (res) =>
{
if (res == Discord.Result.Ok)
{
Debug.LogError("Everything is fine!");
}
});
}

void Update () {
discord.RunCallbacks();
}
}
using System.Collections;
using System.Collections.Generic;

public class Main : TheGameScript
{
private const ulong CLIENT_ID = 1234567890;
public Discord discord;

public override void Init()
{
var discord = new Discord(CLIENT_ID, (UInt64)Discord.CreateFlags.Default);
var activityManager = discord.GetActivityManager();
var activity = new Discord.Activity
{
State = "Still Testing",
Details = "Bigger Test"
};
activityManager.UpdateActivity(activity, (res) =>
{
if (res == Discord.Result.Ok)
{
Debug.LogError("Everything is fine!");
}
});
}

void Update () {
discord.RunCallbacks();
}
}
I have the five discord_game_sdk.* files within the root of my project directory and added the .cs files for the SDK within a folder called DiscordGameSDK. Somehow I still get the following error:
[CS246]: The type or namespace name `Discord' could not be found. Are you missing an assembly reference? in MyProject/Main.cs at [7, 12]
[CS246]: The type or namespace name `Discord' could not be found. Are you missing an assembly reference? in MyProject/Main.cs at [7, 12]
What am I missing? Any help appreciated :D
33 Replies
Elianora
Elianora9mo ago
you're missing some kind of package or using statement that has the Discord type in it
𝔐𝔞𝔱𝔱𝔦𝔫
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.
Elianora
Elianora9mo ago
Can you send a screenshot of what your solution looks like, including the DiscordGameSDK folder?
Angius
Angius9mo ago
It seems they're not distributing the SDK as a nuget
Angius
Angius9mo ago
Yeah, loose C# files
No description
Elianora
Elianora9mo ago
Yeah
𝔐𝔞𝔱𝔱𝔦𝔫
This is my current solution so far
No description
Angius
Angius9mo ago
There's no project file? No Program.cs?
𝔐𝔞𝔱𝔱𝔦𝔫
Where DRP.cs is my main cs
Angius
Angius9mo ago
Well, see what namespace the Discord class is in, and reference that namespace Everything else seems fine If it was VS or Rider I'd tell you to autoimport those namespaces, but this looks like VS Code
𝔐𝔞𝔱𝔱𝔦𝔫
I cna switch to VS right now, may be easier it seems Done, I switched (VS 2022)
Angius
Angius9mo ago
In general, yes, you should only use VS Code if you have a gun to your head and your family is held hostage
𝔐𝔞𝔱𝔱𝔦𝔫
I code in other languages as well, for which VS Code fits my needs more 😅
Elianora
Elianora9mo ago
It looks like Discord is in the Discord namespace, inside Core.cs
𝔐𝔞𝔱𝔱𝔦𝔫
And to use it I have to build my project?
Angius
Angius9mo ago
You need to reference the namespace using Namespace.Bla.Bla.Bla Then you can use classes that reside in Namespace.Bla.Bla.Bla namespace
𝔐𝔞𝔱𝔱𝔦𝔫
But I already tried that and it never works. I tried referencing it via the folder, doesn't work. There is also no highlighting of any available namespaces at all. I tried manually adding it inside my csproj file (via Reference with HintPath), didn't weork either.
Angius
Angius9mo ago
Not getting proper autocomplete, that sounds like misconfigured VSC Or just VSC being VSC Make sure you have DevKit installed
𝔐𝔞𝔱𝔱𝔦𝔫
I am suing VS 2022 now tho, since it should be better for .NET/C# dev Also many people were suggesting "Right Click > Add Existing Item" or similar to fix this, but I don't even have these options at all...
Elianora
Elianora9mo ago
tested it on my machine and it works fine if I just add the folder
Elianora
Elianora9mo ago
No description
Elianora
Elianora9mo ago
all I did was copy + paste the files
𝔐𝔞𝔱𝔱𝔦𝔫
I don't even have the dependencies fiels, like you do... EVen after copy-pasting the files via windows explorer again... At this point I maybe should just create a new project and try again...
Elianora
Elianora9mo ago
all I did was right-click my project (DiscordTest -> New Folder) then copy + pasted the .cs files into the new folder
𝔐𝔞𝔱𝔱𝔦𝔫
I did the same...
Elianora
Elianora9mo ago
it detects them automatically (or at least should) this is in a new console app
Elianora
Elianora9mo ago
not sure
𝔐𝔞𝔱𝔱𝔦𝔫
A new console app with c#, right?
Elianora
Elianora9mo ago
that's all I used, yeah
𝔐𝔞𝔱𝔱𝔦𝔫
Yeah, trying it out as well... Just reinstalling VS as well, just to be sure that I don't miss anything...
jcotton42
jcotton429mo ago
rofl seriously? ... though I guess it would mostly be used by Unity devs
Want results from more Discord servers?
Add your server