Skip to content

Brutalbeard/brutal-discord

Repository files navigation

Brutal-Discord

To add to your discord channels, click right here .

Codacy Security Scan

About

I was using Lita for creating and managing my chat bots, however, since I was mostly using Discord, I was somewhat limited. If I wanted to use a Discord specific feature, like an embed, I was ruining my Lita plugin's abillity to stay agnostic and work for other Lita users.

So, to discord.js I went! Get the of JS, written in Typescript, all hosted on Heroku. Update: Heroku was bein a pain in my ass. Just using my Raspberry Pi now.

I added on a Mongo Database to keep track of events, polls, and user info. I tried out using Redis when using Lita, but it was a pain in the ass. I used MongoDB for my db. It's free version is plenty of power for this app.

I'm always happy to have fellow devs check out the app, and make pull requests and all that. Fork, and send over a pull request at your leisure.

Installation

Application runs on the Node JS framwork, so you'll need that installed. For an editor, I'm a big fan of VS Code, but any popular editor should do.

$ git clone https://github.com/Brutalbeard/brutal-discord
$ cd brutal-discord

Then install all dependencies using npm or yarn

npm install

This should install all the dependencies the app needs onto your computer.

You'll need to make copy of the env_example file, fill it in with all your information, and rename it to .env.

  • Giphy
  • Discord Bot
  • APOD
  • Mongo is a different beast. I'm not gonna try to talk anyone through it here. Long story shortest, you need to create a mongodb that's hosted somewhere in the universe, and then put a bunch of login credentials. I used just the connect URI that was provided with the db, just to make life a little more simple.

Once you've got all that in place, you need to ensure that Typescript is compiling the src folder in the strictly type Javascript, that's put into the build folder. Node will run everything from the build folder. You comile using the command tsc. There's also an option to "watch" for file changes and auto compile again. tsc --watch.

Running the App

Once you've compiled and put in all your .env stuff, you can spin up the app by going to the app's root directory, opening up terminal and running. As of the most recent verion of DiscordJS, you need to run with node version 16. NVM is great for bouncing back and forth between node versions.

$ node .

You'll get some happy text in the terminal letting you know it's up and running. I'm only logging errors in the console, so you won't see much else.

Writing New Commands

You'll edit everything in the /src folder. Don't edit the stuff in /build or you'll go insane.

/src/index.ts runs the show. It's based off the guide supplied by discord.js. Works great, didn't feel like messing with it. I did get a Typescript error when adding commands to the ::Client class. I had to just add an //@ts-ignore to get rid of it.. It was just cause I'm crazy pendantic and didn't want to see the squiggly line. Runs fine regardless.

To make a new command, you'll toss that into /src/commands/. Copy ud.ts and use that as a nice little template. Replace the name and description and what not.

Database Interactions

I'm using the Mongodb Node Driver for all my db interactions.

I considered switching over to Mongoose, but I used Typescript definitions in the /src/definitions folder already, so I didn't see the point in making the switch.

Acknowledgements