To host a DSharpPlus bot 24/7 you run it on a machine that stays on: a Linux VPS with a systemd service that starts it again when it stops, or a bot plan on PlayNHost Discord bot hosting (from US$1.99 a month), where you upload your C# project, pick .NET 10, paste the token and press Start. In our test a DSharpPlus 5.0.0-nightly-02614 bot used about 69 MB of memory on .NET 10. DSharpPlus's own README tells you to use its nightly builds, and its docs list .NET 10 as the only .NET for the 5.0 nightlies, so this page uses one. The steps on PlayNHost:
- On the Discord bot hosting page, click Create Server on a plan. In the order window, answer What is your bot for? with Discord and pick C# (.NET).
- Open your server in the panel. The Set up your bot card on Overview opens at Connect to Discord. Its first step, What runs, should say This bot runs .NET Bot.; click that step to check it, then Continue.
- At Connect to Discord, paste your token into Paste your bot token, click Connect, then Yes, continue.
- At Permissions, tick My code uses this only for the privileged intents your code asks for (the bot below needs none), click Add to a Discord server, then Continue.
- At Your code, click Upload files and upload
Bot.csprojandProgram.csto the main folder, without thebinandobjfolders, or click Connect Git. - On the Bot page, pane Code, pick .NET 10 under Runtime (it is saved as soon as you pick it) and leave Entry file empty.
- Click Start bot and watch Console. The server builds your project first, then your bot prints
Logged in as ...and the card says Your bot is online in Discord.
Creating the bot and its token is explained in How to create a Discord bot and get its token, and the .NET bot type in general (both upload ways, build errors) in How to host a C# (.NET) Discord bot. This page is about DSharpPlus itself: which version to use, what it needs on a server and what to know before you host it.
What we measured
| Library | Version | Memory at rest | Start to Discord's answer, with the build | Program launch to Discord's answer |
|---|---|---|---|---|
| DSharpPlus | 5.0.0-nightly-02614 | 69 MB | 1.9 s | 0.5 s |
| Discord.Net | 3.20.2 | 76 MB | 1.6 s | 0.5 s |
| .NET 8 alone, no library | none | 24 MB | 1.3 s (build and start, no call) | none |
How: on our own node, in a throwaway container set up like a 1 GB bot plan (DSharpPlus on the .NET 10 image, Discord.Net and the row without a library on the .NET 8 image, and the start command of our .NET bot type, which runs dotnet publish on every start), each bot tried to log in with a fake token, which Discord refused; memory is the resident memory 15 seconds after that answer, the first time column runs from the start of the build to the answer, the second from the program's launch, and each figure is the median of runs 2 to 4. The measured DSharpPlus bot only logged in, with DSharpPlus alone (no DSharpPlus.Commands); its first build, which also downloaded DSharpPlus, took 7 seconds.
These are floors: no servers, no cached members, no open gateway session yet. Your own code, the command package and the number of servers your bot is in add to them. To skip the build on every start, you can upload the files you published on your own computer instead of the project (see the C# guide linked above). Compare the numbers with the plans on Discord bot hosting and choose by what your bot does.
A minimal DSharpPlus bot
It registers a /ping slash command, answers it with Pong!, reads the token from DISCORD_TOKEN (the name the panel gives it) and prints a ready line. It needs no privileged intent. Two files in the main folder:
Bot.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02614" />
<PackageReference Include="DSharpPlus.Commands" Version="5.0.0-nightly-02614" />
</ItemGroup>
</Project>
Program.cs
using System.ComponentModel;
using DSharpPlus;
using DSharpPlus.Commands;
using DSharpPlus.Commands.Processors.SlashCommands;
using DSharpPlus.Exceptions;
string? token = Environment.GetEnvironmentVariable("DISCORD_TOKEN");
if (string.IsNullOrWhiteSpace(token))
{
Console.WriteLine("No DISCORD_TOKEN found. Paste your bot token on the Bot page, then restart.");
return 1;
}
// Slash commands only need the Guilds intent, which is not privileged.
DiscordClientBuilder builder = DiscordClientBuilder.CreateDefault(token, SlashCommandProcessor.RequiredIntents);
builder.ConfigureEventHandlers(events => events.HandleSessionCreated((sender, e) =>
{
Console.WriteLine($"Logged in as {sender.CurrentUser.Username}");
return Task.CompletedTask;
}));
builder.UseCommands((services, commands) =>
{
commands.AddCommands(typeof(PingCommand));
commands.AddProcessor(new SlashCommandProcessor());
}, new CommandsConfiguration { RegisterDefaultCommandProcessors = false });
DiscordClient client = builder.Build();
try
{
await client.ConnectAsync();
}
catch (UnauthorizedException)
{
Console.WriteLine("Discord did not accept the bot token. Copy it again (Developer Portal, Bot, Reset Token), paste it on the Bot page, then restart.");
return 1;
}
await Task.Delay(Timeout.Infinite);
return 0;
public class PingCommand
{
[Command("ping"), Description("Replies with Pong!")]
public static ValueTask ExecuteAsync(CommandContext context) => context.RespondAsync("Pong!");
}
On every start the server runs dotnet publish on Bot.csproj and starts Bot.dll. The console says [PlayNHost] Building your bot (the first build downloads packages and can take a minute), then [PlayNHost] Starting your bot, then DSharpPlus's own log lines and Logged in as ..., the line that turns the chip on Overview to Online in Discord. Invite the bot with Add to a Discord server before you try /ping: How to invite your Discord bot to a server.
If the token is wrong
In our test, with a fake token, DSharpPlus's ConnectAsync() failed with this error:
UnauthorizedException: Unauthorized: Unauthorized
Before that, DSharpPlus logs a warning, [DSharpPlus.Net.RestClient] [Warn] Received non-success status code Unauthorized making a request to https://discord.com/api/v10/users/@me. The bot above catches that UnauthorizedException and prints Discord did not accept the bot token. Copy it again (Developer Portal, Bot, Reset Token), paste it on the Bot page, then restart. instead, then stops with exit code 1. To fix it, open the Discord Developer Portal, your application, Bot, and click Reset Token; Discord shows the new token once. On our Bot page, pane Discord, click Replace token, paste it, click Save token, then Restart now. When Discord refuses a check of the saved token, the pane shows Discord did not accept it.
What to know about DSharpPlus on a server
- Which version: on NuGet, the newest stable DSharpPlus is 4.5.3 (24 Aug 2026), and the 5.0 nightlies are listed as pre-releases (the newest, 5.0.0-nightly-02614, on 1 Nov 2026). The README says you should, as a rule, use the nightlies, its documentation covers only them, and the docs say no support is given for 4.5. A package numbered plain
5.0.0also exists on NuGet, but it is unlisted, dates from May 2023 and does not have the API on this page: do not writeVersion="5.0.0". - .NET 10 for the nightlies: 5.0.0-nightly-02614 is built for .NET 10 only, and DSharpPlus's docs list .NET 10 as the only .NET for the 5.0 nightlies, so set
net10.0in your project and .NET 10 as the Runtime. With .NET 8 (recommended) picked, the build stops withNETSDK1045. DSharpPlus 4.5.3 targets .NET Standard 2.0, and the docs list .NET 8 to 10 as supported for 4.5; it has the older API (new DiscordClient(new DiscordConfiguration { ... })). - Pin the nightly, no wildcard. Write the exact nightly number, as above. By NuGet's documented rules a floating version takes the highest match, stable versions included, and ignores whether a package is listed, so
5.0.0-nightly-*would resolve to that old unlisted5.0.0, which counts as higher than every nightly. The server restores and builds your project on every start, so an exact number also keeps it from changing under you. To update, change the number inBot.csprojand restart. - Commands: the command framework is the separate package
DSharpPlus.Commands, which handles slash and text commands.DSharpPlus.SlashCommandsis obsolete andDSharpPlus.CommandsNextis scheduled to follow, so older tutorials that use them need changes. Keep every DSharpPlus package on the same nightly number. - Intents:
SlashCommandProcessor.RequiredIntentsis onlyGuilds, which is not privileged. The text command processor, on by default, reacts to the!prefix and to mentions of the bot; in servers, Discord sends a bot the text of messages that do not mention it only with the privileged Message Content intent. The bot above switches the default processors off and adds only the slash one. If you add Message Content, switch it on in the Developer Portal too and tick My code uses this for it, or Discord closes the connection. See Fix "Used disallowed intents" on your Discord bot. - Discord's command list follows your code. At each start, with no
DebugGuildId, DSharpPlus.Commands reads your application's global commands from Discord, creates the new ones, edits the changed ones and deletes the ones your code no longer has, except an Activity entry point. A command you delete from your code disappears from Discord at the next start, and so does a global command another program registered for the same application. - Logs: DSharpPlus's default logger writes to the console at Information level and above. Once Discord accepts the token, Console shows its start-up line,
DSharpPlus; version ...; with a refused token it logs only the[Warn]line above.builder.SetLogLevel(...)changes the level. - Crashes: when the bot exits, as the bot above does on a refused token, the panel starts it again right away, building it again first. If it stops again within a minute of that, it stays stopped and Console says why.
Host it yourself on a Linux VPS
On a VPS, build the bot on your own computer and run only the result on the server. Publish it with the .NET 10 SDK:
dotnet publish Bot.csproj -c Release -o publish
On Ubuntu 24.04 the .NET 10 runtime is in Ubuntu's own packages:
sudo apt update
sudo apt install dotnet-runtime-10.0
dotnet --list-runtimes
Make a user for the bot and copy the publish folder to the server (for example with scp -r), then into its folder:
sudo useradd --system --create-home --home-dir /opt/mybot mybot
sudo cp -r publish/. /opt/mybot/
sudo chown -R mybot: /opt/mybot
Keep the token out of your code, in a file only root can read:
sudo sh -c 'echo "DISCORD_TOKEN=your-token" > /etc/mybot.env'
sudo chmod 600 /etc/mybot.env
Create /etc/systemd/system/mybot.service:
[Unit]
Description=DSharpPlus bot
Wants=network-online.target
After=network-online.target
[Service]
User=mybot
WorkingDirectory=/opt/mybot
EnvironmentFile=/etc/mybot.env
ExecStart=/usr/bin/dotnet /opt/mybot/Bot.dll
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Start it now and at every boot, then follow its output:
sudo systemctl daemon-reload
sudo systemctl enable --now mybot
sudo journalctl -u mybot -f
Restart=always starts the bot again 5 seconds after it exits or crashes, but not after you stop it with systemctl stop. To update, publish again, copy the new files over the old ones and run sudo systemctl restart mybot. On Debian, .NET is not in the distribution's own packages; Microsoft's install instructions cover it.
Self-hosting or a bot plan
On a VPS you manage yourself:
- Operating system updates and security, and .NET runtime upgrades.
- Publishing and copying each new build, the service file, the token file and its permissions.
- Reading
journalctlto find out why the bot stopped. - Backups of anything your bot stores.
In return a VPS runs anything you install on it, and nothing is built there.
On a PlayNHost bot plan the panel does this for you:
- .NET 6, 8, 9 or 10 from a picker, and the build: upload the project and press Start.
- The token, checked with Discord before it is saved, stored encrypted and given to your code as
DISCORD_TOKEN. - An invite link with the permissions you pick, and a Privileged intents card that checks which ones are switched on in your Developer Portal.
- Starting the bot again after a crash, and a banner above Console when the bot runs out of memory.
- Upload, Git deploys and backups from the panel.
Questions people ask
Should I use DSharpPlus 4.5.3 or a 5.0 nightly?
For a new bot, a 5.0 nightly: the DSharpPlus team says so in the README, and its documentation and support cover only 5.0. An existing 4.5 bot still runs on our plans as it is, with Runtime set to the .NET version its project targets; moving it to 5.0 means changing code, because 5.0 builds the client with DiscordClientBuilder instead of new DiscordClient(new DiscordConfiguration { ... }), and its commands come from DSharpPlus.Commands instead of the old command packages.
The build fails with NETSDK1045. What now?
Your project targets a newer .NET than the Runtime you picked. A 5.0 nightly needs net10.0 and .NET 10: set it on the Code pane, click Save and start the bot again.
Why does every start take longer than the bot itself needs?
Because the server runs dotnet publish before each start, so a change you upload is always built. In our test that made the start 1.9 seconds against 0.5 seconds for the program alone. To skip the build, publish on your computer and upload the files from the publish folder instead of the project.
DSharpPlus or Discord.Net on PlayNHost?
Both run on the same .NET bot type. The table above has the memory we measured for each. Discord.Net has stable releases (3.20.2 on 8 Oct 2026) that build on .NET 8, the recommended runtime; DSharpPlus asks you to follow its nightlies on .NET 10. Choose the API you prefer. Discord.Net steps: How to host a C# (.NET) Discord bot.
Ready to run your DSharpPlus bot around the clock? See the plans on Discord bot hosting.



