bot.guilds.forEach(async (guild, id) => { const row = await bot.db.query(`SELECT * FROM serverInfo WHERE serverID = ${guild.id}`) if (row[0].muteRoleID !== null) { const mtr = guild.roles.find(r => r.id === row[0].muteRoleID) if (guild.me.permissions.has(['MANAGE_ROLES', 'VIEW_AUDIT_LOG'], true)) { guild.channels.forEach(async (channel, id) => { if (channel.type === 'category') { const prmToCheck = ['SEND_MESSAGES', 'ADD_REACTIONS', 'EMBED_LINKS', 'ATTACH_FILES', 'SPEAK', 'USE_VAD']; for (const prm of prmToCheck) { if (!channel.permissionsFor(mtr).has(prm, false) !== true) { setTimeout(() => { channel.overwritePermissions(mtr, { prm: false }, `Updating perms for ${channel.type} named ${channel.name}`).catch(console.error); console.log(`Updated perms for mute role ${mtr.name} & ${mtr.id} in ${channel.guild.name} & ${channel.guild.id} of ${channel.type} & ${channel.id}`); }, Math.floor((Math.random() * Math.floor(10000)) + 1000)); } else if (!channel.permissionsFor(mtr).has(prm, false) === true) { console.log(`Channel ${channel.id} already has ${prm} denied for role ${mtr}`); } } } else if (channel.type === 'voice') { const nullPrm = ['SEND_MESSAGES', 'ADD_REACTIONS', 'EMBED_LINKS', 'ATTACH_FILES']; const denyPrm = ['SPEAK', 'USE_VAD']; for (const prm of nullPrm) { if (channel.permissionsFor(mtr).has(prm, false) === true || false) { setTimeout(() => { channel.overwritePermissions(mtr, { prm: null }, `Updating perms for ${channel.type} named ${channel.name}`).catch(console.error); console.log(`Updated perms for mute role ${mtr.name} & ${mtr.id} in ${channel.guild.name} & ${channel.guild.id} of ${channel.type} & ${channel.id}`); }, Math.floor((Math.random() * Math.floor(10000)) + 1000)); } else if (channel.permissionsFor(mtr).has(prm, false) === null) { console.log(`Channel ${channel.id} already has ${prm} nullified for role ${mtr}`); } } for (const prm of denyPrm) { if (!channel.permissionsFor(mtr).has(prm, false) !== true) { setTimeout(() => { channel.overwritePermissions(mtr, { prm: false }, `Updating perms for ${channel.type} named ${channel.name}`).catch(console.error); console.log(`Updated perms for mute role ${mtr.name} & ${mtr.id} in ${channel.guild.name} & ${channel.guild.id} of ${channel.type} & ${channel.id}`); }, Math.floor((Math.random() * Math.floor(10000)) + 1000)); } else if (!channel.permissionsFor(mtr).has(prm, false) === true) { console.log(`Channel ${channel.id} already has ${prm} denied for role ${mtr}`); } } } else if (channel.type === 'text') { const nullPrm = ['SPEAK', 'USE_VAD']; const denyPrm = ['SEND_MESSAGES', 'ADD_REACTIONS', 'EMBED_LINKS', 'ATTACH_FILES']; for (const prm of nullPrm) { if (channel.permissionsFor(mtr).has(prm, false) === true || false) { setTimeout(() => { channel.overwritePermissions(mtr, { prm: null }, `Updating perms for ${channel.type} named ${channel.name}`).catch(console.error); console.log(`Updated perms for mute role ${mtr.name} & ${mtr.id} in ${channel.guild.name} & ${channel.guild.id} of ${channel.type} & ${channel.id}`); }, Math.floor((Math.random() * Math.floor(10000)) + 1000)); } else if (channel.permissionsFor(mtr).has(prm, false) === null) { console.log(`Channel ${channel.id} already has ${prm} nullified for role ${mtr}`); } } for (const prm of denyPrm) { if (!channel.permissionsFor(mtr).has(prm, false) !== true) { setTimeout(() => { channel.overwritePermissions(mtr, { prm: false }, `Updating perms for ${channel.type} named ${channel.name}`).catch(console.error); console.log(`Updated perms for mute role ${mtr.name} & ${mtr.id} in ${channel.guild.name} & ${channel.guild.id} of ${channel.type} & ${channel.id}`); }, Math.floor((Math.random() * Math.floor(10000)) + 1000)); } else if (channel.permissionsFor(mtr).has(prm, false) === true) { console.log(`Channel ${channel.id} already has ${prm} denied for role ${mtr}`); } } } }); } } });