commit
91b9764d03
6 changed files with 58 additions and 44 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -108,3 +108,6 @@ commands/
|
|||
events/
|
||||
bot.js
|
||||
config.json
|
||||
|
||||
# Linux Environment Files
|
||||
*.swp
|
||||
|
|
12
README.md
12
README.md
|
@ -12,15 +12,19 @@ Copy the config template file and fill in the strings.
|
|||
{
|
||||
"token": "",
|
||||
"prefix": "",
|
||||
"commands": "",
|
||||
"events": ""
|
||||
"commands": [
|
||||
""
|
||||
],
|
||||
"events": [
|
||||
""
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
* **Token:** Your bot's token
|
||||
* **Prefix** The command prefix
|
||||
* **Commands:** The folder name containing your commands
|
||||
* **Events:** The folder name containing your events
|
||||
* **Commands:** An array of the folders which contain your commands
|
||||
* **Events:** An array of the folders which contain your events
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
|
@ -40,8 +40,12 @@ An example configuration:
|
|||
{
|
||||
"token": "<YOUR-BOT-TOKEN>",
|
||||
"prefix": "!",
|
||||
"commands": "commands",
|
||||
"events": "events"
|
||||
"commands": [
|
||||
"commands"
|
||||
],
|
||||
"events": [
|
||||
"events"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -33,10 +33,10 @@ class client extends Client {
|
|||
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.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 (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";
|
||||
|
||||
this._config = config;
|
||||
|
|
|
@ -7,38 +7,42 @@ class util {
|
|||
}
|
||||
|
||||
loadCommand(name, args, message) {
|
||||
stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => {
|
||||
if (err == null) {
|
||||
let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`);
|
||||
let command = new commandFile();
|
||||
for (let c = 0; c < this._client.config.commands.length; c++) {
|
||||
let folder = this._client.config.commands[c];
|
||||
|
||||
let requiredConfigs = command.requiredConfigs;
|
||||
stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => {
|
||||
if (err == null) {
|
||||
let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`);
|
||||
let command = new commandFile();
|
||||
|
||||
for (let i = 0; i < requiredConfigs.length; i++) {
|
||||
if (!this._client.config[name]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
|
||||
if (!this._client.config[name][requiredConfigs[i]]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
|
||||
}
|
||||
let requiredConfigs = command.requiredConfigs;
|
||||
|
||||
let requiredRoles = command.roles;
|
||||
for (let i = 0; i < requiredConfigs.length; i++) {
|
||||
if (!this._client.config[name]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
|
||||
if (!this._client.config[name][requiredConfigs[i]]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
|
||||
}
|
||||
|
||||
for (let i = 0; i < requiredRoles.length; i++) {
|
||||
if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) {
|
||||
message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
let requiredRoles = command.roles;
|
||||
|
||||
command[command.run]({
|
||||
"command": name,
|
||||
"arguments": args,
|
||||
"client": this._client,
|
||||
"message": message,
|
||||
"config": config
|
||||
});
|
||||
} else if (err.code === 'ENOENT') {
|
||||
// FILE DOESN'T EXIST
|
||||
}
|
||||
});
|
||||
for (let i = 0; i < requiredRoles.length; i++) {
|
||||
if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) {
|
||||
message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
command[command.run]({
|
||||
"command": name,
|
||||
"arguments": args,
|
||||
"client": this._client,
|
||||
"message": message,
|
||||
"config": config
|
||||
});
|
||||
} else if (err.code === 'ENOENT') {
|
||||
// FILE DOESN'T EXIST
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
loadEvents() {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
class command {
|
||||
constructor(run) {
|
||||
this.run = run;
|
||||
|
||||
this._roles = [];
|
||||
this._requiredConfigs = [];
|
||||
}
|
||||
|
||||
// Description
|
||||
|
@ -31,8 +34,6 @@ class command {
|
|||
}
|
||||
|
||||
// Roles
|
||||
_roles = [];
|
||||
|
||||
get roles() {
|
||||
return this._roles;
|
||||
}
|
||||
|
@ -42,8 +43,6 @@ class command {
|
|||
}
|
||||
|
||||
// Config
|
||||
_requiredConfigs = [];
|
||||
|
||||
get requiredConfigs() {
|
||||
return this._requiredConfigs;
|
||||
}
|
||||
|
|
Reference in a new issue