Discord.js slash command permission system not working

Viewed 271

This is the main code for the permission setting.

const run = (client) => __awaiter(void 0, void 0, void 0, function* () {
    const commandFiles = glob_1.default.sync(process.cwd() + "/src/commands/**/*{.ts,.js}");
    const guild = client.guilds.cache.get(config_json_1.default.guildId);
    commandFiles.map(value => {
        Promise.resolve().then(() => __importStar(require(value))).then((file) => __awaiter(void 0, void 0, void 0, function* () {
            exports.commands.set(file.info.name, file);
            const command = yield guild.commands.create(file.info);
            if (file.permission == undefined || file.permission == "@everyone")
                return;
            const json = (file.permission == "admin" ? {
                id: config_json_1.default.adminRole,
                permission: true,
                type: "ROLE"
            } : {
                id: config_json_1.default.freelancerRole,
                permission: true,
                type: "ROLE"
            });
            command.permissions.add({
                permissions: [json]
            });
        }));
    });

I have commissioned a dev for a discord bot and everything is working apart from the fact that anybody can use any command. He has a custom permission system that sets it with the above method. However, this does not work. I have debugged the config role ids, file.permission is set and he is positive it works. File.permission is set with exports.permission = "admin"; in a command file and defaultpermission is true.

1 Answers

Discord doesn't have permission called admin, you have to use ADMINISTRATOR permission instead!

Related