Startup → Docker Image → .NET 8 (or .NET 10 if your project targets it). There are two ways to run it.
Way 1: we build it
Upload your .csproj, your .cs files and .env (not the bin and obj folders). On start we run dotnet publish and start the result.
Building needs about 1 GB of memory. If the console says Killed, use way 2.
Way 2: publish on your computer (best for small plans)
dotnet publish -c Release -o publish
Upload everything in the publish folder, type your bot’s .dll in Main file (like MyBot.dll), and turn off Install packages on start.
The code (Discord.Net)
On your computer: dotnet new console -n MyBot, then in that folder dotnet add package Discord.Net and dotnet add package DotNetEnv.
Program.cs:
using Discord;
using Discord.WebSocket;
DotNetEnv.Env.Load();
var client = new DiscordSocketClient();
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);
.env holds the token: DISCORD_TOKEN=your-token-here.
Good to know
- DSharpPlus or NetCord work the same way: add their package instead of Discord.Net.
- Message content: add
GatewayIntents.MessageContentto the client’s config, and switch on Message Content Intent in the Developer Portal → your app → Bot.
More help: Run your Discord bot 24/7.