Changed commands and events to be an array, allowing multiple folders
This commit is contained in:
parent
1d075e5a2c
commit
bf09d9bed0
3 changed files with 43 additions and 35 deletions
12
README.md
12
README.md
|
@ -12,15 +12,19 @@ Copy the config template file and fill in the strings.
|
||||||
{
|
{
|
||||||
"token": "",
|
"token": "",
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"commands": "",
|
"commands": [
|
||||||
"events": ""
|
""
|
||||||
|
],
|
||||||
|
"events": [
|
||||||
|
""
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* **Token:** Your bot's token
|
* **Token:** Your bot's token
|
||||||
* **Prefix** The command prefix
|
* **Prefix** The command prefix
|
||||||
* **Commands:** The folder name containing your commands
|
* **Commands:** An array of the folders which contain your commands
|
||||||
* **Events:** The folder name containing your events
|
* **Events:** An array of the folders which contain your events
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,10 @@ class client extends Client {
|
||||||
if (typeof config.token != "string") throw "Token is not a string";
|
if (typeof config.token != "string") throw "Token is not a string";
|
||||||
if (typeof config.prefix != "string") throw "Prefix is not a string";
|
if (typeof config.prefix != "string") throw "Prefix is not a string";
|
||||||
|
|
||||||
if (typeof config.commands != "string") throw "Commands is not a string";
|
if (typeof config.commands != "object") throw "Commands is not a string";
|
||||||
if (!existsSync(`${process.cwd()}/${config.commands}`)) throw "Commands folder doesn't exist";
|
if (!existsSync(`${process.cwd()}/${config.commands}`)) throw "Commands folder doesn't exist";
|
||||||
|
|
||||||
if (typeof config.events != "string") throw "Events is not a string";
|
if (typeof config.events != "object") throw "Events is not a string";
|
||||||
if (!existsSync(`${process.cwd()}/${config.events}`)) throw "Events folder doesn't exist";
|
if (!existsSync(`${process.cwd()}/${config.events}`)) throw "Events folder doesn't exist";
|
||||||
|
|
||||||
this._config = config;
|
this._config = config;
|
||||||
|
|
|
@ -7,6 +7,9 @@ class util {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCommand(name, args, message) {
|
loadCommand(name, args, message) {
|
||||||
|
for (let c = 0; c < this._client.config.commands.length; c++) {
|
||||||
|
let folder = this._client.config.commands[c];
|
||||||
|
|
||||||
stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => {
|
stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => {
|
||||||
if (err == null) {
|
if (err == null) {
|
||||||
let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`);
|
let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`);
|
||||||
|
@ -40,6 +43,7 @@ class util {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loadEvents() {
|
loadEvents() {
|
||||||
let eventFiles = readdirSync(`${process.cwd()}/${this._client.config.events}/`);
|
let eventFiles = readdirSync(`${process.cwd()}/${this._client.config.events}/`);
|
||||||
|
|
Reference in a new issue