add checks for presence of user/role perms before checking

merge-requests/1/merge
Matthew 2019-10-27 21:21:26 -04:00
parent 0633564e6a
commit 9e5c9da6e2
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 13 additions and 4 deletions

View File

@ -16,13 +16,22 @@ export default class {
const resolved: Command = this.client.util.resolveCommand(command);
if (!resolved) return;
if (resolved.guildOnly && !(message.channel instanceof TextChannel)) return;
const hasUserPerms: boolean = resolved.permissions.users.includes(message.author.id);
let hasUserPerms: boolean;
if (resolved.permissions.users) {
hasUserPerms = resolved.permissions.users.includes(message.author.id);
} else {
hasUserPerms = true;
}
let hasRolePerms: boolean = false;
if (resolved.permissions.roles) {
for (const role of resolved.permissions.roles) {
if (message.member && message.member.roles.includes(role)) {
hasRolePerms = true; break;
}
}
} else {
hasRolePerms = true;
}
if (!hasRolePerms && !hasUserPerms) return;
if (!resolved.enabled) { message.channel.createMessage(`***${this.client.stores.emojis.error} This command has been disabled***`); return; }
const args: string[] = noPrefix.slice(1);