async cmd_regis({ commands, gid }: cmd_regis_op) { if (gid) { const guild = this.guilds.cache.get(gid); await guild.commands .set(commands) .then(async (cmd) => { const role = (cmd_name: string) => { const perms = this.slash_cmd.find( (x) => x.name === cmd_name ).perms; if (!perms) return null; return guild.roles.cache.filter((x) => x.permissions.has(perms) && !x.managed); } const full_perms = cmd.reduce((acc, x) => { const roles = role(x.name); if (!roles) return acc; const permissions = roles.reduce((a, v) => { return [ ...a, { id: v.id, type: "USER", permission: true }, ]; }, []); return [ ...acc, { id: x.id, permissions } ] }, []); await guild.commands.permissions.set({ fullPermissions: full_perms }) }) } else { this.guilds.fetch().then((guilds) => { guilds.forEach(async (guild) => { const all_guild = this.guilds.cache.get(guild.id) await this.application?.commands .set(commands) .then(async (cmd) => { const role = (cmd_name: string) => { const perms = this.slash_cmd.find( (x) => x.name === cmd_name ).perms; if (!perms) return null; return all_guild.roles.cache.filter((x) => x.permissions.has(perms) && !x.managed); } const full_perms = cmd.reduce((acc, x) => { const roles = role(x.name); if (!roles) return acc; const permissions = roles.reduce((a, v) => { return [ ...a, { id: v.id, type: "ROLE", permission: true }, ]; }, []); return [ ...acc, { id: x.id, permissions } ] }, []); await all_guild.commands.permissions.set({ fullPermissions: full_perms }) }) }) }) } }