TravBot-v3/docs/Overview.md

2.8 KiB

Table of Contents

Introduction

This is a brief overview that'll describe where and how to add new features to TravBot. For more details on specific functions, head over to the documentation. TravBot uses the Onion Lasers Command Handler to load and setup commands. Also, if you ever want to see the definition of a function or its surrounding types and you're using VSCode, put your cursor at the word you want to go to and press [F12].

Setting up the development environment

  1. npm install
  2. npm run dev (runs the TypeScript compiler in watch mode, meaning any changes you make to the code will automatically reload the bot)

Note: Make sure to avoid using npm run build! This will remove all your dev dependencies (in order to reduce space used). Instead, use npm run once to compile and build in non-dev mode.

Note: If you update one of the APIs or utility functions, make sure to update the documentation.

Adding a new command

To add a new command, go to src/commands and create a new .ts file named as the command name. Then, use and expand upon the following template.

import {Command, NamedCommand, RestCommand} from "onion-lasers";

export default new NamedCommand({
    async run({send, message, channel, guild, author, member, client, args}) {
        // code
    }
});

Adding a new non-command feature

If the feature you want to add isn't specifically a command, or the change you're making involves adding event listeners, go to src/modules and create a file. Code written here won't be automatically loaded, so make sure to open src/index.ts and add an import statement at the bottom.

import "./modules/myModule";

This will just run whatever code is in there.

Listening for events

Rather than have an events folder which contains dynamically loaded events, you add an event listener directly via client.on("...", () => {}). (See why if you're curious.) The client can be imported from the index file.

import {client} from "..";

client.on("message", (message) => {
	//...
});

As long as you make sure to add that import statement in the index file itself, the event(s) will load.

Just make sure you instantiate the client before you import a module or you'll get a runtime error.

index.ts

import {Client} from "discord.js";

export const client = new Client();

//...

import "./modules/myModule";