donbot
discord bot framework based on discord.js
Installation and Usage
Install via npm
npm install --save donbot
Import the base client
const Bot = ;
Provide the bot with login data and connect. The Bot
class extends the discordjs.Client so all methods and properties can be found in an bot object.
const bot = token: "LOGIN_TOKEN" prefix: "+" owner: "OWNER_ID"; bot;
token
is the login token obtained from the discord dev website
prefix
is the prefix each command must have to be recognized as one. For this example we will pe using +
as our prefix.
onwer
is the id of the user who owns the server. This user will always be allowed to execute commands
First Command
Let's try to make a simple command that replies with the users name
First we have to import the class each command is based on
const TextCommand = ;
Then we make a new class extending TextCommand
.
In the constructor we have to call the super()
method and pass it an object with command specific arguments
{ super command: "username" ; }
The functionality is made with a run()
. The method takes the bot, the original message and a parsedMessage which has all arguments parsed out of the message and ready to use in your code;
public async { message;}
The full code will look something like this
const Bot TextCommand = ; const client = token: "YOUR_TOKEN" prefix: "+" owner: "YOUR_ID"; client { super command: "username" } public async { message; }