Starterbot - Discord

A simple boilerplate discord bot you can easily build upon

dependenciesversion commit license

If you are running this on Glitch you can skip: "Prerequisites, Setup, Run, PM2"


Prerequisites are the same as in basic bot so follow those:


The setup is super simple. Run this command to clone the repo:

git clone -b master

Enter bot folder and run:

npm install
node setup.js


Run bot with: node bot.js


PM2 is my favorite process manager for node.js applications. It will restart anytime the app crashes and can reload when changes in the code are detected. First install pm2 globally.

npm i -g pm2

To run your bot run:

pm2 start bot.js


All commands are stored in the commands folder and follow a very specific syntax. You may add more .js files but they must follow the same structure.

module.exports = {
'name': 'ping',
'description': 'Checks the bot\'s latency',
'usage': 'ping',
'owneronly': false,
execute: (bot, args, msg, config) => {`🏓 Pong! \`${Math.floor(}ms\``);

An example of adding a command with the proper syntax:

module.exports = {
'name': 'hello',
'description': 'Bot will say hello back',
'usage': 'hello',
'owneronly': false,
execute: (bot, args, msg, config) => {`Hello ${}!`);


The execution function is invoked when the command is typed into Discord. It passes 4 important parameters that will be used in our code.

execute: (bot, args, msg, config)


The bot object refers to the Client constructor.

Though others use client, we use bot to keep it simple.

All the extended methods and properties are still the same in the Discord.js Docs

console.log(bot.user.tag) // 'Testerbot#1542'
console.log(bot.uptime) // 1239123
console.log( // 34
console.log(bot.guilds.size) // 3
bot.login('token goes here') // Logs in
bot.on('guildMemberAdd', member => {
member.send(`Welcome to the server!`); //Emitted when a user joins the server


This is an object that stores all of your commands to make them easily accessible.

eval: {
name: 'eval',
description: 'Evaluates javascript code',
usage: 'eval <code>',
owneronly: true,
execute: [Function: execute]
help: {
name: 'help',
description: "Checks the bot's commands",
usage: 'help <commandname>',
owneronly: false,
execute: [Function: execute]
ping: {
name: 'ping',
description: "Checks the bot's latency",
usage: 'ping',
owneronly: false,
execute: [Function: execute]
reboot: {
name: 'reboot',
description: 'Reboots the bot',
usage: 'reboot',
owneronly: true,
execute: [Function: execute]
stats: {
name: 'stats',
description: "Checks the bot's stats",
usage: 'stats',
owneronly: false,
execute: [Function: execute]


Arguments is a popular way to take parameters in a message and to do what we please with them.

$commandname these are my arguments turns into ["these","are","my","arguments"]

console.log(args.join(' ')) // 'these are my arguments'
//Since array's index starts at zero
console.log(args[0]) // 'these'
console.log(args[1]) // 'are'
console.log(args[2]) // 'my'
console.log(args[3]) // 'arguments'
//To check if the user supplied arguments
if (!args) return console.log('User supplied no arguments')
//To get specific arguments
if (args[0] !== somevariable) return console.log('User supplied invalid arguments')
//Some commands like:
//$ban @user reason
//require you to use this to get the full reason
let reason = args.slice(1).join(' ')
console.log(reason) // Returns the rest of the args


The msg object refers to parameter we passed in the message event in bot.js

console.log(msg.content) // 'Message content appears here'
console.log( // 'andrejarrell'
console.log( // '123456789012345678'
//Methods'Hello there!')
msg.delete() // Deletes message
msg.react('😃') // Reacts with emoji


config refers to the config.json file in the root directory.

"prefix": "$",
"ownerid": "123456789012345678",
"token": "NTYxMDM3MDM1Mzc3MjYyNTkz.D385Ig.FfFodONLqmHVZKIGh7SokUq26oM"
console.log(config.prefix) // '$'
console.log(config.ownerid) // '123456789012345678'
console.log(config.token) // 'NTYxMDM3MDM1Mzc3MjYyNTkz.D385Ig.FfFodONLqmHVZKIGh7SokUq26oM'


All commands have properties that identify them and let us know what they do.

name: 'reboot',
description: 'Reboots the bot',
usage: 'reboot',
owneronly: true,


Type: string

name: 'eval', // the name of the command


Type: string

description: 'Reboots the bot', // the description of the command


Type: string

usage: 'reboot', // make sure to include arguments if they exist


Type: boolean

owneronly : true, // stops users from using owner command


I recommend using Digital Ocean for your hosting needs. It has a simple UI and no hidden charges.