@jadl/cmd
Version:
A command handler for JADL
24 lines (23 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserPerms = void 0;
const Decorators_1 = require("../../utils/Decorators");
const jadl_1 = require("jadl");
const CommandError_1 = require("../../structures/CommandError");
const builders_1 = require("@jadl/builders");
exports.UserPerms = Decorators_1.Decorators.createCommandDecorator(([_perms], cmd) => {
const perms = Array.isArray(_perms) ? _perms : [_perms];
cmd.canRun.push(function CheckUserPermissions(int) {
if (!int.member)
return true;
const missing = perms.filter((x) => !jadl_1.PermissionUtils.has(BigInt(int.member.permissions), x));
if (missing.length > 0) {
throw new CommandError_1.CommandError(new builders_1.Embed()
.color('Red')
.description(`You're missing the following permissions: ${missing
.map((x) => jadl_1.humanReadablePermissions[x])
.join(', ')}`));
}
return true;
});
});