Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Added Require role #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/commands/General/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config = require(ROOT_PATH + '/config.json');
module.exports.run = (bot, message, args) => {

let { log: parsed, findCommand } = require(ROOT_PATH + '/utils/commandHandler');

let rrole;
let embed = new MessageEmbed()
.setTitle("Help!").setColor("BLUE").setDescription("Commands Help list");

Expand All @@ -23,13 +23,15 @@ module.exports.run = (bot, message, args) => {

let aliases = "`" + cmd.aliases.join('`, `') + "`";
let subCommands = cmd.subCommands != null ? `\`${cmd.subCommands.map(x => x.name).join('`, `')}\`` : null;

rrole = cmd.requiredRole == null ? "none" : cmd.requiredRole;
if(rrole != "none") rrole = message.guild.roles.cache.find(r => r.id === rrole);
let help = [
`**name:** ${cmd.name}`,
`**description:** ${cmd.description}`,
cmd.aliases.length == 0 ? null : `**aliases:** ${aliases}`,
`**usage:** ${usage}`,
`**requiredPermission:** ${cmd.requiredPermission == null ? "none" : cmd.requiredPermission}`,
`**requiredRoles:** ${rrole}`,
subCommands != null ? `**subcommands:** ${subCommands}` : null
]

Expand All @@ -52,4 +54,4 @@ module.exports.info = {
requiredPermission: null,// default is null
aliases: ['?', "h"], // default is null
usage: '[command] [subcommand]' // default is null
}
}
3 changes: 2 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"token": "",
"guild": "",
"prefix": ".",
"missing_permission": "You require the `{PERMISSION}` permission to use this command."
"missing_permission": "You require the `{PERMISSION}` permission to use this command.",
"missing_role": "You require the `{ROLE}` role to use this command"
}
8 changes: 7 additions & 1 deletion src/utils/commandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ let findCommand = (list, commandsList, message) => {
else if (cmd != null && cmd.subCommands != null) temp = cmd.subCommands.find(x => x.name == command || x.aliases.includes(command));

if (message != null) {
if (temp != null && temp.requiredRole != null && !message.member.roles.cache.find(r => r.id === temp.requiredRole)) { // role check
let rname = message.guild.roles.cache.find(r => r.id === temp.requiredRole)
message.channel.send({ content: config.discord.bot.missing_role.replace("{ROLE}", rname.name) }); // Missing role message
return;
};
if (temp != null && temp.requiredPermission != null && !message.member.permissions.has(temp.requiredPermission)) { // Permission check
message.channel.send({ content: config.missing_permission.replace("{PERMISSION}", temp.requiredPermission) }); // Missing permission message
return;
Expand Down Expand Up @@ -122,6 +127,7 @@ let loadCommands = (rootPath) => {
usage: null,
aliases: [],
requiredPermission: null,
requiredRole: null,
path: path.split('\\').pop(),
size: 0,
depth: (!parent ? 0 : parent.depth),
Expand Down Expand Up @@ -222,4 +228,4 @@ module.exports = {
loadCommands,
findCommand,
log
};
};