Commented util.js

This commit is contained in:
vylpes 2020-10-30 18:34:51 +00:00
parent c76532db32
commit 2ec2e81853

View file

@ -30,32 +30,39 @@ class util {
// Loop through all the required configs of the command
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`;
}
// If the command doesn't have the configs in the config string, throw an error
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 requiredRoles = command.roles;
// Get the roles required for this command to run
let requiredRoles = command.roles;
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;
}
// Loop through all roles required
for (let i = 0; i < requiredRoles.length; i++) {
// If the user doesn't have a required role, don't run the command and let the user know
if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) {
message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`);
return;
}
}
// Get the ids of the users that are only permitted to run this command
let users = command.users;
// If the user isn't in the list, don't run the command
if (!users.includes(message.member.id)) {
message.reply(`You do not have permission to run this command`);
return;
}
command[command.run]({
"command": name,
"arguments": args,
"client": this._client,
"message": message,
"config": config
// Run the command and pass the command context with it
command[command.run]({
"command": name,
"arguments": args,
"client": this._client,
"message": message,
"config": config
});
} else if (err.code === 'ENOENT') {
// FILE DOESN'T EXIST
@ -64,18 +71,28 @@ class util {
}
}
// Load the events
loadEvents() {
// Loop through all the event folders
for (let e = 0; e < this._client.config.events.length; e++) {
// Get the current folder to check
let folder = this._client.config.events[e];
// Get the files inside of this folder
let eventFiles = readdirSync(`${process.cwd()}/${folder}/`);
// Loop through all the files in the folder
for (let i = 0; i < eventFiles.length; i++) {
// Get the event name, by taking the command file and removing the ".js" from the end
let eventName = eventFiles[i].split('.')[0];
// Get the file of the event
let file = require(`${process.cwd()}/${folder}/${eventName}.js`);
// Initialise the event class
let event = new file;
// Set the client to emit to this event
this._client.on(eventName, event[event.run]);
}
}