NEW 📢 Black Friday: our launch offer ends 30 Nov. Up to 70% off your first month on every game!See plans
Black FridayUp to 70% off your first month, ends 30 NovEnds in 9d 02h 53mBlack FridayUp to 70% off your first month, ends 30 NovEnds in 9d 02h 53mBlack FridayUp to 70% off your first month, ends 30 NovEnds in 9d 02h 53m

How to host a C# (.NET) Discord bot

Discord bot hostingUpdated Nov 6, 20266 min read

To run a C# bot (Discord.Net, DSharpPlus or any .NET library) on your bot server:

  1. Check the bot's card on Overview says .NET Bot; if not, on the Bot page, pane Code, click Change what runs next to Runtime and pick it.
  2. Pick the .NET version under Runtime on the Code pane.
  3. Upload your project with its .csproj (the server builds it on every start), or your published files, in Files.
  4. Paste your token on the Bot page, pane Discord, and click Connect.
  5. Press Start and watch Console.

1. Check the type

The bot's card on Overview says what runs, for example Discord bot - .NET Bot. If it says another language, on the Bot page, pane Code, click Change what runs next to Runtime (on a computer, the type label at the top of the page opens the same dialog) and pick .NET Bot. Your files stay unless you tick Delete my existing files and start clean. See How to switch your bot to another language.

2. Pick the .NET version

On the Bot page, pane Code, card How it runs, set Runtime: .NET 8 (recommended), or .NET 6, 9 or 10. Match it to TargetFramework in your project: net8.0 for .NET 8, net10.0 for .NET 10.

3. Upload your bot: two ways

A. Upload the project, the server builds it

  1. In Files, upload your .csproj and source files. Leave out the bin and obj folders. To upload a folder, zip it, upload the zip, tick it and click Unzip.
  2. Leave Entry file empty to use the .csproj in the main folder. If there are several, type the one to build, for example MyBot.csproj.

On every start the server runs dotnet publish in Release mode, then starts the result. The console says [PlayNHost] Building your bot (the first build downloads packages and can take a minute). A project with its own <AssemblyName> starts too: the server picks the built program that has a .runtimeconfig.json next to it. On a server set up before this worked, click Reinstall at the bottom of the Code pane once; your files stay.

B. Upload published files

  1. On your computer run dotnet publish -c Release -o publish.
  2. Upload everything in the publish folder to the main folder in Files.
  3. Set Entry file to the .dll, for example MyBot.dll, and click Save. Left empty, the server finds it from the .runtimeconfig.json file next to it.

Published files start faster and nothing is built on the server, so all of your plan's memory goes to the bot.

The How it runs card of a .NET bot with an empty Entry file and Runtime .NET 8 (recommended).

Your code on GitHub? The .NET Bot type can download it: How to deploy and update your Discord bot from GitHub.

4. A small Discord.Net 3 project

MyBot.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Discord.Net" Version="3.*" />
  </ItemGroup>
</Project>

Program.cs

using Discord;
using Discord.WebSocket;

var client = new DiscordSocketClient(new DiscordSocketConfig { GatewayIntents = GatewayIntents.Guilds });
client.Log += msg => { Console.WriteLine(msg); return Task.CompletedTask; };
client.Ready += () => { Console.WriteLine($"Logged in as {client.CurrentUser}"); return Task.CompletedTask; };

await client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("DISCORD_TOKEN"));
await client.StartAsync();
await Task.Delay(Timeout.Infinite);

5. Paste the token and start

On the Discord pane, paste the token and click Connect. Your code reads it as DISCORD_TOKEN. Press Start and open Console. When Logged in as appears, the chip on Overview turns to Online in Discord.

How much memory a Discord.Net bot uses

We measured it on one of our own servers on 6 November 2026, in a throwaway container set up like a 1 GB bot plan, with a fake token that Discord refused. A minimal Discord.Net 3.20.2 bot on .NET 8 used about 76 MB of memory. Discord answered 1.6 s after the start, of which 1.1 s was the dotnet publish step the server runs on every start and 0.5 s the bot itself. .NET 8 on its own used 24 MB, and a DSharpPlus 5.0 nightly bot on .NET 10 used 69 MB. A bot that has connected and joined servers uses more, so check RAM on the Usage card after a day of real use. Memory is the resident memory 15 seconds after Discord's answer, the median of three runs after a warm-up run.

Discord.Net does not stop on a wrong token. LoginAsync checks only the token's format; StartAsync then connects in the background, reports Discord's refusal through the Log event as Discord.Net.HttpException: The server responded with error 401: 401: Unauthorized and tries again. Keep the client.Log line of the sample above: without it, a bot with a wrong token prints nothing and looks running.

Console lines you may see

LineWhat to do
[PlayNHost] Your bot is not set up yet: no project or published dll was found.Upload a .csproj or your published files to the main folder, or set Entry file.
[PlayNHost] The build failed. Read the errors above, fix them and press Start.The compiler errors are just above (lines with error CS). Fix them, upload again and press Start.
NETSDK1045 in the build outputYour project targets a newer .NET than the Runtime you picked. Pick the matching one.

Good to know

Already hosting your bot somewhere else? Move it to us

OUR LATEST BLOGS