Introduction Last updated: 18/03/2020

Welcome to the TravBot documentation. this page will guide you through the codebase at a glance.

1.1 Directory tree

This section will cover the directory tree.


  /
  ├── assets/
  |   └── [image files for ravi]
  ├── commands/
  |   ├── storage/
  |   |   └── UserData.json
  |   └── [command files]
  ├── events/
  |   └── [Discord.JS event files]
  ├── modules/
  |   └── [modules used by bot]
  ├── colours.json
  ├── config.js.example
  ├── config_base.txt
  ├── index.js
  ├── package.json
  ├── package-lock.json
  ├── setup.js
  └── whois.json
						
Folder/file explanation:

The assets folder contains all images for the .ravi command. This might be subject of change in a later release.

The commands folder contains, as you might expect, all command files. These are being loaded from modules/functions.js, which has the command handler.

The events folder contains all Discord.JS events. These are seperate files which are called upon emittance of certain events.

The modules folder contains our command handler, and the logger. The command handler takes care of loading and unloading commands upon client request. The logger takes care of sending messages (warnings, errors, etc) to the console.

1.2 Modules

This section will cover the modules.

Functions

This module provides basic bot functionality. It currently contains a JSON object which stores the default values for the bot settings, a function to properly display permission levels, and our command handler which can load and unload command files

The module is exported and imported in every single command file.

Logger

This module contains all code required for our beautiful console log. It has various cases on which it triggers, such as warn, error, cmd, and three less significant ones.

This module is exported and imported in all event files.

1.3 Events

This section will cover the events. All of these events are customizable to your liking.

They use the Logger module for logging events to the console.

ready

This event is executed once the client is ready. It logs the client user ID, the amount of users in all guilds, and the total number of guilds.

After that, it sets the client activity to Listening to [default prefix]help

reconnecting

This event is executed once the client is trying to reconnect.

It logs a message stating the client is reconnecting, and sets the same client activity as the ready event once it is reconnected.

disconnected

This event is executed once the client has lost connection.

It logs a message stating that the client has lost connection.

message

This event is executed every time a message is received on the client side.

It checks if the message was sent by a bot, then checks if the message starts with a prefix, after that it checks if the command which is being called exists, and finally it checks if the user has the required permission level to execute the command.

error

This event is executed every time Discord.JS sends an error.

It stringifies the error, and then logs it to the console.

guildCreate

This event is executed every time the client is added to a guild.

It logs the guild name, guild ID, owner of the guild, and the ID of the owner.

It then sends a message to a channel ID stating the same as the console.

guildDelete

This event is executed every time the client is removed from a guild.

It logs the guild name, and the guild ID.

It then sends a message to a channel ID stating the same as the console.

guildMemberAdd

This event is executed every time a user joins a guild the client is present in.

It is only used if the guild has configuration option welcomeEnabled set to true.

Installation

This section will cover installing and setting up the bot.

2.1 Requirements

This section will cover setting up all requirements.

Setting up the bot requires two things:

2.2 Setting up

This section will cover setting up the bot.

Once you have installed git, cd to a directory where you would like to install the bot.

Next, run:


  git clone https://github.com/keanuplayz/TravBot
							

After you have cloned the repository, cd to the bot directory with:


  cd TravBot
							

Danger

Be aware: one of the dependencies used is better-sqlite3. Better-SQLite3 depends on integer, which requires windows-build-tools to be installed globally. Make sure to install this by opening up an Administrator PowerShell window and running npm install --global --production windows-build-tools.

You can now install the bot dependencies by running:


  npm install
							

Make sure to run node setup.js to complete the bot setup.

2.3 Running

Note

Make sure to do any personalisation before starting the bot.

If you have not ran this yet, run node setup.js to set up the bot. You will need to input the bot token and the owner's user ID. The owner will have the highest pemission level, so make sure to enter your own ID!

After installing all dependencies, you should now be set to run the bot with:


  node index.js