A multi-purpose discord bot easily upgradable with custom commands build with node.js and TypeScript
Works with :
- Node 12.2
- Npm 6.9
Create a .env file
touch .env
This file contains the API keys.
Add at least the BOT_TOKEN
variable that contains the bot's secret key.
And then
npm install
npm start
A step by step series of examples that tell you how to get a development env running
You can add a custom command :
First, you need to create a class (extending the AbstractCommand class) in the commands
folder.
export default class YourClass extends AbstractCommand
You can use the ARGS_COUNT
constant that will take the number of arguments your command should take :
static readonly ARGS_COUNT = 0;
Then create a execute
static function :
public static execute(args: Array<string>, message: Message): void{
if (args.length === this.ARGS_COUNT) {
//your code here
} else {
YourClass.sendArgsCountError(message)
}
}
The function will be called when the command will be executed.
- The first param is an array of strings that contains all the params the user gave.
- The second param is the Message object received from discord.js
You don't have to check the arguments count, but it's recommended.
Finally, add an export line to the index.ts file :
export {default as YourCommand} from "./YourClass";
Your command
is the command the user will give after the prefix.
You can change the prefix in CommandPointer
- Node 12.2
- npm 6.9 - Dependency Management
- Intellij IDEA - IDE
This project is licensed under the MIT License - see the LICENSE file for details