commit
91b9764d03
6 changed files with 58 additions and 44 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -107,4 +107,7 @@ dist
|
||||||
commands/
|
commands/
|
||||||
events/
|
events/
|
||||||
bot.js
|
bot.js
|
||||||
config.json
|
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": "",
|
"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
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,12 @@ An example configuration:
|
||||||
{
|
{
|
||||||
"token": "<YOUR-BOT-TOKEN>",
|
"token": "<YOUR-BOT-TOKEN>",
|
||||||
"prefix": "!",
|
"prefix": "!",
|
||||||
"commands": "commands",
|
"commands": [
|
||||||
"events": "events"
|
"commands"
|
||||||
|
],
|
||||||
|
"events": [
|
||||||
|
"events"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -125,4 +129,4 @@ module.exports = message;
|
||||||
2. In the `constructor()` you need to call `super(run)`, replacing `run` with a string of the name of the method which will run when the event gets triggered.
|
2. In the `constructor()` you need to call `super(run)`, replacing `run` with a string of the name of the method which will run when the event gets triggered.
|
||||||
3. Create a method using the name you set in `super(run)`, with the parameters being as per your event's paramaters in the discord.js documentation.
|
3. Create a method using the name you set in `super(run)`, with the parameters being as per your event's paramaters in the discord.js documentation.
|
||||||
|
|
||||||
> **Note:** The name of the event file will determine what event it will be triggered on. For example, if you want to have an event trigger everytime a message is sent, put into your event folder a file called `message.js` and follow the steps above.
|
> **Note:** The name of the event file will determine what event it will be triggered on. For example, if you want to have an event trigger everytime a message is sent, put into your event folder a file called `message.js` and follow the steps above.
|
||||||
|
|
|
@ -33,14 +33,14 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = client;
|
module.exports = client;
|
||||||
|
|
|
@ -7,38 +7,42 @@ class util {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCommand(name, args, message) {
|
loadCommand(name, args, message) {
|
||||||
stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => {
|
for (let c = 0; c < this._client.config.commands.length; c++) {
|
||||||
if (err == null) {
|
let folder = this._client.config.commands[c];
|
||||||
let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`);
|
|
||||||
let command = new commandFile();
|
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();
|
||||||
|
|
||||||
let requiredConfigs = command.requiredConfigs;
|
let requiredConfigs = command.requiredConfigs;
|
||||||
|
|
||||||
for (let i = 0; i < requiredConfigs.length; i++) {
|
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]) 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`;
|
if (!this._client.config[name][requiredConfigs[i]]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let requiredRoles = command.roles;
|
let requiredRoles = command.roles;
|
||||||
|
|
||||||
for (let i = 0; i < requiredRoles.length; i++) {
|
for (let i = 0; i < requiredRoles.length; i++) {
|
||||||
if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) {
|
if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) {
|
||||||
message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`);
|
message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
command[command.run]({
|
command[command.run]({
|
||||||
"command": name,
|
"command": name,
|
||||||
"arguments": args,
|
"arguments": args,
|
||||||
"client": this._client,
|
"client": this._client,
|
||||||
"message": message,
|
"message": message,
|
||||||
"config": config
|
"config": config
|
||||||
});
|
});
|
||||||
} else if (err.code === 'ENOENT') {
|
} else if (err.code === 'ENOENT') {
|
||||||
// FILE DOESN'T EXIST
|
// FILE DOESN'T EXIST
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadEvents() {
|
loadEvents() {
|
||||||
|
@ -55,4 +59,4 @@ class util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = util;
|
module.exports = util;
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
class command {
|
class command {
|
||||||
constructor(run) {
|
constructor(run) {
|
||||||
this.run = run;
|
this.run = run;
|
||||||
|
|
||||||
|
this._roles = [];
|
||||||
|
this._requiredConfigs = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
|
@ -31,8 +34,6 @@ class command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roles
|
// Roles
|
||||||
_roles = [];
|
|
||||||
|
|
||||||
get roles() {
|
get roles() {
|
||||||
return this._roles;
|
return this._roles;
|
||||||
}
|
}
|
||||||
|
@ -42,8 +43,6 @@ class command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
_requiredConfigs = [];
|
|
||||||
|
|
||||||
get requiredConfigs() {
|
get requiredConfigs() {
|
||||||
return this._requiredConfigs;
|
return this._requiredConfigs;
|
||||||
}
|
}
|
||||||
|
@ -53,4 +52,4 @@ class command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = command;
|
module.exports = command;
|
||||||
|
|
Reference in a new issue