Discord Bot

In my spare time, I like to play games with my friends online and we use Discord to speak to each other. So I wanted to see if I could make a Discord bot for just our own enjoyment and this is how I developed and deployed it.

Register your Bot

Firstly, you need to create your bot on the Discord site . Once you have created your Discord 'Application' you should be able to see your public key, client ID and client secret. We will need these later.

Discord.Net

This is what I used to develop my Discord bot using C#. You can find the github for this nuget package here. You will then need to create a new dotnet core console app and install the Discord.Net nuget package. I then followed this guide to get a simple bot running locally on my own PC.

Deploying your Bot

There are a lot of options out there for this but I'd like to share the provider I used for this, DigitalOcean. You can pay $5 a month for their cheapest tier Linux VPS running Ubuntu. Then you need to build your Discord bot for the Linux environment. I was using Ubuntu-20.10 and dotnet core 3.1 so you may have to swap these values depending on what you are using. Run this command to in your projects directory dotnet publish -c release -r ubuntu.16.04-x64 Now we have built our Discord bot for Linux all we have to do now is copy it over to our server and run it. To copy the built files run the following command, make sure to input your own user and ip for your Linux server scp -r YourProjectDirectory/src/bin/release/netcoreapp3.1/ubuntu.20.10-x64/publish user@IPAddress:/YourBotName This will copy all the files to the root directory of your server and place them in a new directory with the name of your bot. Next we need to add the permissions to run the app chmod 777 ./appname Then run the app as a background process so that it does not stop once you leave the terminal nohup ./appname &