Creating a Discord Bot in Ruby
So, what do you do? You make a Discord Bot with Ruby.
Starting with a Template I didn’t actually have one single template (you heard me right, I copied stuff from like three sites). No, but seriously, you just have to put the pieces together. So I went with a mixture of the example bots in the discordrb Repository and this article. I guess with “How to Make a Simple Discord Bot in Ruby to Annoy your Friends”, the friends were the friendly helpers on the Discord API server. Due to my small knowledge about Ruby and the discordrb gem, I wasn’t really sure what I was doing all of the time.
The “What do I want to do” Phase That one was actually pretty quick for me. I wanted to make a Discord Bot to short links with. After I discovered that I wasn’t the only one with this idea, I still continued, remembering what Justin Duke has told me. He basically said, that if you find out you’re not the only one with a cool idea, don’t abandon it, but try to do better than your competition (he’s a cool guy, check him out).
Starting with the main feature: Shorten Links I wanted to use kutt.it because of the cool features and it being free. Later on, I noticed that that’s not going to happen since it didn’t short with my custom domain so I had to change plans. I used Rebrandly because of the free custom domains. I’ll have to see if the free plan is enough in the long term. Now, the third site I gathered code from comes in. I used their cool site to automatically generate an API request using net/http. It worked an I was happy.
Some extra features I added some stuff like a help command, a version command, and a ping command. The ping one is also from the discordrb examples. In a later commit, I also added the automatic addition of http(s):// to the link you want to shorten if you didn’t already add it because Rebrandly only takes links which include that.
Publishing on GitHub The last step was, to publish the bot on GitHub and upload it to a Server. At first, I didn’t know that a program you run via ruby yourprogram.rb stops after a certain amount of time. After some help from my Discord API guys, I used Screen which basically creates always-on sessions.
That’s it. If you’d like to check it out, this is the repository. Feel free to copy some stuff but I can’t promise that the code is perfect. It works and that’s important, right?