// Commands.js //
const { Perms } = require("../Validation/Permission");
const { Client } = require("discord.js");
const { promisify } = require("util");
const { glob } = require("glob");
const PG = promisify(glob);
const { resourceUsage } = require("process");
/**
* @param {Client} client
*/
module.exports = async (client) => {
commandsArry = [];
(await PG(`${process.cwd()}/Commands/*/*.js`)).map(async(file) => {
const command = require(file);
if(!command.name) return;
if(command.permission) {
command.defaultPermission = false
}
commandsArry.push(command);
client.commands.set(command.name, command);
console.log(` Command Loaded ` + command.name);
});
client.on("ready", async () => {
const MainGuild = await client.guilds.cache.get("649379388110012445");
MainGuild.commands.set(commandsArry).then((command) => {
const Roles = (commandName) => {
const cmdPerms = commandsArry.find((c) => c.name === commandName).perms;
if(!cmdPerms) return null;
return MainGuild.roles.cache.filter((r) => r.permissions.has(cmdPerms) && !r.managed);
};
const fullPermissions = command.reduce((ac, x) => {
const roles = Roles(x.name);
if (!roles) return ac;
const permissions = roles.reduce((a, v) => {
return [ ...a, {id: v.id, type: "ROLE", permission: true}];
}, []);
return [...ac, {id: x.id, permissions}];
}, []);
MainGuild.commands.permissions.set({ fullPermissions });
});
});
};
E:\staff\Botdiscord\Handlers\Commands.js:34
MainGuild.commands.set(commandsArry).then((command) => {
^
TypeError: Cannot read properties of undefined (reading 'commands')
at Client.<anonymous> (E:\staff\Botdiscord\Handlers\Commands.js:34:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)