I recently got a RPi3B for my birthday and I just made my own C# discord bot using Discord.Net I created some commands and figured it'd be cool to run it on my RPi so I don't have to have my laptop on all the time, so I uploaded my bot to bitbucket and cloned it onto my RPi (on raspbian btw) I can program a little, but I really do not know what mono and .Net core etc are used for, but I read I needed mono to run a C# program, so I installed this on my RPi, so my project.exe would run, but it keeps on disconnecting (it runs just fine on my laptop) Here (https://github.com/RogueException/Discord.Net/issues/703) I found someone with the same problem, but I couldn't figure out what I should try now, I've tried installing .Net core 2 in many shady ways, but the walkthroughs I tried didn't seem to work
Is there any way to fix this? Thanks in advance :)
1 Answer 1
I know this is a rather old post, but I do know the answer and since it's the top most google search result, I figure this could still be helpful for people in the future.
About .NET Core
I created my C# discord bot in visual studio 2017 as a .NET Core project. .NET Core works similar to java, where your program doesn't get run by the OS directly, but rather by a program that is run on the OS. This makes it so that your code is platform independent and you can use your same code on both Linux and Windows for example, as long as your OS has the .NET Core runtime installed.
Discord.Net
I installed the Discord.Net package using nuGet in visual studio in my project as my interface with the discord API. Discord.Net is compatible with .NET Core and therefore we can easily port it to the raspberry pi.
Getting your bot to run on the raspberry
DISCLAIMER: I used a raspberry running Raspbian, so I know it works on that, but I don't know if this works on systems that run on a different OS.
First you need to get the .NET Core runtime on your raspberry. I used the tutorial on this website to install .NET Core 2.0 on my raspberry. You connect to the raspberry using putty and follow the steps in that article as follows:
- run
sudo apt-get install curl libunwind8 gettext
to install all dependencies - run
curl -sSL -o dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Runtime/release/2.0.0/dotnet-runtime-latest-linux-arm.tar.gz
to download the 2.0.0 release of the dotnet runtime - run
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
to create a folder for the runtime and extract it. - run
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
to create a symbolic link
The second step is to set up the environment on your computer to send your programs to the raspberry. I used this website to do that. Assuming you use visual studio 2017 and .NET Core, you don't need to install anything to work with dotnet in your powershell.
For this to work, you need to have putty installed from here, because this approach depends on some features from putty.
The steps in the article are executed in powershell on your own computer as follows:
- run
dotnet new -i RaspberryPi.Template::*
to install the templates for dotnet - run
cd path/to/a/directory
to navigate to a folder where you want to create a new project - run
dotnet new coreiot -n HelloRaspbian
to create a new project called 'HelloRaspbian' - run
cd HelloRaspbian
to navigate into the project that just got created - run
Invoke-WebRequest http://cakebuild.net/download/bootstrapper/windows -OutFile build.ps1
to download the build&deploy script into your project. - Open build.cake and edit the lines under ARGUMENTS (WITH DEFAULT PARAMETERS FOR LINUX (Ubuntu 16.04, Raspbian Jessie, etc) so that they refer to your raspberry.
- write your program in your newly created project using visual studio. If you want to use an existing project, you can copy all files and folders over to the new project. Don't forget to install the Discord.Net package in your new project using nuGet in visual studio.
- run
.\build.ps1
to build your project and to send it to the raspberry. I noticed that non-code files don't get copied over, so I copied those over manually.
Your program should now be on your raspberry and you can start it like usual.
I hope this helps!