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.