A modular discord bot, made during my free time.
You can start making a module by creating a folder named after your module, and making a module.js
file inside.
modules
├── module1
│ └── module.js
├── module2
│ └── module.js
...
A module file must contain a class that is exported with module.exports
or the ES6 counterpart.
Preferably, the class should be named after the module.
Inside the class, you will be able to make Commands and use built-in state functions.
import Module from "components/module";
export default class Module1 extends Module {
constructor() {
super()
this.config = {
name: 'Module1',
description: 'My first module!'
}
}
}
You can make classes containing functions which will be shared across every modules.
module1
└── utils
├ Utility1.js
└ Utility2.js
class Utility1 {
constructor(bot) {
this.foo() = function(bar){
return 'foo' + bar
}
}
}
module.exports = Utility1
Then, the function can be used in a module (provided you have done the step 1.4).
foobar = bot.module1.utility1.foo('bar')
//Returns 'foobar'
A command is made inside a module or submodule, and has 4 parameters
- The way to write the command in discord
- A description of the command
- The arguments types
- The process that is ran when the command is written
import Module from "components/module";
export default class Module1 extends Module {
super()
this.config = {
name: 'Module1',
description: 'My first module!'
}
constructor() {
this.command1 = new Command(
'<string>',
'My first command!',
[{type:'string'}],
function(msg,arg){
msg.reply(arg[0]);
}
)
}
}
And then you can run it on discord your discord server :
>command1 test
bot says : @User, test