Create your own Discord cat bot07 Apr 2018
I’ve been using Discord for a while, primarily to chat to friends while playing games. It’s replaced TeamSpeak and Mumble entirely for pretty much everybody I know online - for good reason! It’s easy to use and simple to administer, requiring only a web browser.
I’ve also wanted to write a bot for a ages and after joking about it for a bit, I was inspired by my friends Jason Browne and Jordan Campbell. They have had their own various bots over the years so I thought I’d have a stab at it. I decided I wanted to make a simple cat bot with that could perform two simple actions:
- Post cat pictures to Discord.
- Post random cat facts to Discord.
Originally I chose to rely on third party APIs to provide cat facts and pictures - the pictures from the cat api work great and I still use them but the cat facts were a little vulgar and I didn’t really feel comfortable using them. I decided to roll my own and host it on Heroku. I’ve set up swagger so you can easily see how the API works and have a play with it if you’d like to know more by clicking here. I found the Heroku platform surprisingly pleasant to work with. You have to mostly use a set of supported languages to be able to host an app but you get a lot for free. You easily get enough free hosting time to run an application 24/7.
There is free github integration so I get an automatic rebuild and deploy every time I push a change to the master branch of my cat fact api repository. It’s a little annoying that on the free tier the container that hosts your project will get suspended every 30 minutes unless a request is made to it. This does limit what you can do project wise, but overall it’s a very compelling package with slick administration tools that I do recommend.
I had real fun with the cat fact API. I went a little overboard with it by adding the aforementioned swagger support as well as automated testing with the Chai fluent assertion library and the Mocha testing framework. It was good to learn and contrast with what I normally use for similar work in C#, Fluent Assertions and NUnit. I was surprised with how much I could get done with so little work.
All in all, if you want to write your own chat bot for Discord or similar apps such as Slack I’d heavily recommend giving it a try. It’s way easier than you think!