Hubot-Discobot, an adapter for Discord.js

Discord is a great online platform, think of it as Slack for gamers, only better. As a Slack clone it is prime territory for a good bot to help your community channels be a little cooler. On the PWN9 Discord – we have a bunch of 3rd party bots, but it’s always more fun as a developer to create and maintain your own. So I set out to research frameworks and bots to get my own bot running on Discord.

Because I’ve adopted Javascript as my “go-to” language of preference, I settled on using Discord.js for the Discord API. Initially a few years ago when Discord came I started developing my own bot entirely from scratch. At some point, I can’t recall when or the version number, but Discord.js changed so dramatically I would have had to rewrite my entire bot from scratch. Instead of that I figured I’d just look for a bot framework, and since I was familiar with Hubot – from an IRC bot I had used, and also on Ryver, which is another Slack clone, I decided to look for a discord adapter for Hubot.

An adapter is for hubot is something that allows the basic bot framework, which was designed by GitHub, to connect to a chat room. I ended up settling on hubot-disbot – which was pretty basic but unlike a bunch of others I found on NPM, it was functional. Sadly, the author archived their project on GitHub, and like many of the other discord/hubot adapters on NPM it was using a really old version of Discord.js. So I decided to fork disbot into hubot-discobot.

I didn’t really have to do a lot to disbot. I fixed up a few minor issues and upgraded a bunch of dependencies in the package.json, started running my new version privately on my discord server for testing, then figured I should publish it. But I did have one major issue… I wanted to be able extend the special features provided by the latest Discord.js into the scripts for Hubot. The scripts by the way, is the system in Hubot in which you can implement your own connections and ideas into the functional robot. I wasn’t entirely should how well it would work, but I simply added a single line in coffeescript to the discord.coffee script for discobot.

@robot.client = @discord

My thinking was, the Discord.js documentation and examples use “client” to setup their constructor, so I basically do the same, but with “robot.client” where robot is the hubot framework. Then I created a quick simple example script, and voila, worked like a charm. I was able to get my hubot, on Discord, to do Discord level things, like “set playing game”.

I posted a basic version of the bot we use on Pwn9 for a quick start to a working Discord Hubot – It’s Trembot, feel free to use it for your own Discord!

Leave a Reply

Your email address will not be published. Required fields are marked *