for (const [id, guild] of bot.guilds) { 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)) { for (const [id2, channel] of guild.channels) { 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) { await 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}`); } 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) { await 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}`); } 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) { await 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}`); } 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) { await 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}`); } 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) { await 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}`); } else if (channel.permissionsFor(mtr).has(prm, false) === true) { console.log(`Channel ${channel.id} already has ${prm} denied for role ${mtr}`); } } } } } } }