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
Elianora3mo 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
Elianora3mo ago
Can you send a screenshot of what your solution looks like, including the DiscordGameSDK folder?
Angius
Angius3mo ago
It seems they're not distributing the SDK as a nuget
Angius
Angius3mo ago
Yeah, loose C# files
No description
Elianora
Elianora3mo ago
Yeah
𝔐𝔞𝔱𝔱𝔦𝔫
This is my current solution so far
No description
Angius
Angius3mo ago
There's no project file? No Program.cs?
𝔐𝔞𝔱𝔱𝔦𝔫
Where DRP.cs is my main cs
Angius
Angius3mo 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
Angius3mo 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
Elianora3mo ago
It looks like Discord is in the Discord namespace, inside Core.cs
𝔐𝔞𝔱𝔱𝔦𝔫
And to use it I have to build my project?
Angius
Angius3mo 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
Angius3mo 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
Elianora3mo ago
tested it on my machine and it works fine if I just add the folder
Elianora
Elianora3mo ago
No description
Elianora
Elianora3mo 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
Elianora3mo 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
Elianora3mo ago
it detects them automatically (or at least should) this is in a new console app
Elianora
Elianora3mo ago
not sure
𝔐𝔞𝔱𝔱𝔦𝔫
A new console app with c#, right?
Elianora
Elianora3mo 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
jcotton422mo ago
rofl seriously? ... though I guess it would mostly be used by Unity devs
Want results from more Discord servers?
Add your server
More Posts
Marshal.GetActiveObject("Word.Application") fall in exceptionI'm working on a `.NET Framework` console application, I have added the `Microsoft.Office.Interop.WMigrating to Microsoft.IdentityModel.JsonWebTokens .net6 => .net8Hi, I am migrating a project which uses Duende as identity server + Ocelot gateway from .NET 6 to .NProcess working set is twice as commited managed memoryHi! I have an ASP.NET Core 8 app running on Linux in Docker. It's memory usage is limited by 512M. Resource based authorization with IdentityHello, I have the following setup in my asp.net core project: A `Workspace` model that has a bunch o✅ is .net 8.0 is not compatibleHey hi guys I'm new to this group and .net I just started learning .net I don't have any experience Help with why code is returning this way.Hello, I'm a CS student learning C# for the first time and i'm having some confusion on why my code Named pipe connection over network error (The username or password is incorrect)When running a solution where one machine runs a server and a second machine runs a client connectinDifference algorithm that Git usesHello! Quick rundown: I have a need to detect changes in custom bytecode sequences. Essentially, I Do I add my Models in the IdentityDbContext from the template?I'm trying to create a project, where I'll have two types of users (regular and admin) and I'll haveneed help adding authenticationHow can i add some basic google authentication to my API? (When I want to use an ASP.NET web api con