Preparation for making a discord bot

Developing a Discord Bot requires quite a bit of setup, but you only need to do this once and then you can create many more JavaScript projects.

Node JS

Download and Install Node from: https://nodejs.org/en/

NodeDL.png

Node Packet Manager

Once installed, create a folder for your project. Call it what your bot will be named or just call it DiscordBot for now. Next up we need to install Discord.js, this is done using Node Package Manager (NPM). We need to open a command prompt to do this, hold down Shift + Right Click and then select open command prompt. If you cannot see the option, open the start menu and search for cmd and hit enter. Then type cd <PATH TO YOUR FOLDER> for example if my folder was located on my Desktop I would type: cd C:\Users\Dan\Desktop\DiscordBot. Replace “Dan” with the account name on Windows.

Installing discord js

Type “npm init” in the command prompt. This will then ask a series of questions. Fill them in as you see fit. If you are not sure on any, just leave them blank.

PackageSetup.png

Once complete, it’s now time to install Discord.js. Type into the command prompt: “npm install discord.js”

npminstall.png

Setting up a linter

You can program your discord bot using Notepad or Notepad++, however these don’t offer syntax highlighting. I am using WebStorm to develop in, however, this is a paid product. You can download Visual Studio Code which is a light weight editor for multiple languages.

vscode.png

Next download the Linter for Visual Studio Code: npm install eslint

Finally, install the plugin for Visual Studio code.

eslint.png

Linter Tweaks

Create a file in the root of your project folder. Call this file .eslintrc.json and copy the following code into the file or download it from Github.

{
	"extends": "eslint:recommended",
	"env": {
		"node": true,
		"es6": true
	},
	"parserOptions": {
		"ecmaVersion": 2019
	},
	"rules": {
		"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
		"comma-dangle": ["error", "always-multiline"],
		"comma-spacing": "error",
		"comma-style": "error",
		"curly": ["error", "multi-line", "consistent"],
		"dot-location": ["error", "property"],
		"handle-callback-err": "off",
		"indent": ["error", "tab"],
		"max-nested-callbacks": ["error", { "max": 4 }],
		"max-statements-per-line": ["error", { "max": 2 }],
		"no-console": "off",
		"no-empty-function": "error",
		"no-floating-decimal": "error",
		"no-inline-comments": "error",
		"no-lonely-if": "error",
		"no-multi-spaces": "error",
		"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
		"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
		"no-trailing-spaces": ["error"],
		"no-var": "error",
		"object-curly-spacing": ["error", "always"],
		"prefer-const": "error",
		"quotes": ["error", "single"],
		"semi": ["error", "always"],
		"space-before-blocks": "error",
		"space-before-function-paren": ["error", {
			"anonymous": "never",
			"named": "never",
			"asyncArrow": "always"
		}],
		"space-in-parens": "error",
		"space-infix-ops": "error",
		"space-unary-ops": "error",
		"spaced-comment": "error",
		"yoda": "error"
	}
}