Skip to content

MitchCodes/Discord.ts-Buddy-Boilerplate

Repository files navigation

Discord.ts-Buddy-Boilerplate

Disclaimer

This package is developed for using TypeScript in Node. Some of the below features may not be very helpful when working in a purely JavaScript environment.

About

The purpose of this repository is to provide an example and template for using Discord.ts-Buddy to create Discord bots using TypeScript. The purpose of Discord.ts-Buddy itself is to speed up the development time of developing the bots.

Requirements

  • Node 6.0.0 or up
  • node-gyp installed to build libraries necessary for production Discord.js
    • Requires Python. See the Python installation instructions from the node-gyp link
  • Any other requirements from discord.js

Usage

Normal Usage

git clone https://github.com/MitchCodes/Discord.ts-Buddy-Boilerplate.git
cd Discord.ts-Buddy-Boilerplate
yarn (OR) npm install
npm run build

After installation and building, the application is ready to run. Running main.js in the build folder with node will start the program. By default the config file will not have a valid token in it so you will have to provide one.

npm run start

Docker

Given that the Docker daemon is running:

git clone https://github.com/MitchCodes/Discord.ts-Buddy-Boilerplate.git
cd Discord.ts-Buddy-Boilerplate
docker build -t my-discord-bot .
docker run -it my-discord-bot

Again, a valid bot token is not provided in the configuration file and will need to be provided. Replace "my-discord-bot" with whatever name you would want for your Docker image.

Boilerplate Features

In addition to the features you get from Discord.ts-Buddy, here are the features that this repository has for development that I think could be useful as an example:

  • Fully-featured package.json with every necessary Discord.js dependency for production
  • All code written in TypeScript
  • Webpack for building the application for deployments
  • Optional configuration file setup that works together with webpack when building to development and production
  • Dockerfile for creating an image to easily spin up a container with the bot. See usage for more information
  • Unit tests using Jest

Configuration File Setup

There are three optional files that you can create in the root folder next to package.json and the like:

  • config.common.json
    • Necessary to have if you want to have any config file
  • config.dev.json
  • config.prod.json

On build, webpack will take the config.common.json file (if it exists) and merge it with the appropriate dev or prod file (if they exist) depending on whether you built with npm run build or npm run build-prod. The file that gets generated is named config.json. NOTE: It merges arrays by adding them together instead of replacing the entire array. Be careful of this.

Although this repo comes with nconf, you can obviously use any configuration library you want. The webpack config file merging will happen anyway.

IDE Notes

This was developed using Visual Studio Code so that is the one that I will talk about although any IDE would work.

Visual Studio Code

The jest extension is definitely helpful. The launch.json file was tricky to get working with Jest so below there is an example of the one that is working well for me.

launch.json example:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/src\\main.ts",
            "outFiles": [
               "${workspaceFolder}/build/**/*.js"
            ],
            "sourceMaps": true
        },
        {
            "name": "Debug Jest Tests",
            "type": "node",
            "request": "launch",
            "port":9222,
            "cwd": "${workspaceRoot}",
            "runtimeArgs": ["--inspect=9222",
                "${workspaceRoot}/node_modules/jest/bin/jest.js",
                "--config",
                "${workspaceRoot}/jest.config.js",
                "--runInBand",
                "--coverage",
                "false",
                "--no-cache"],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "sourceMaps": true,
            "outFiles": [
                "${workspaceFolder}/build/**/*.js",
                "${workspaceFolder}/__tests__/**/*"
            ],
            "env":{
                "NO_WEBPACK_MIDDLEWARE": "false"
            }
        }
    ]
}

About

Discord bots in TypeScript made easier with a boiler-plate template using Discord.ts-Buddy helper classes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published