Channel Permissions

hey im trying to get a specific role permission in a channel and copy its perms with another role in another word duplicatiing the role permission in the same channel. for example i got a role named Verified with set of permissions in some channels , and i wanna add another role named Verifed 2 to those channels which has verified role in them and copying its perm. this is what ive done so far but im stuck at where i should get channels where they only have Verified role perm
8 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Violet
VioletOP2y ago
const role = interaction.options.getRole('role');
const sRole = interaction.options.getRole('s_role');

await interaction.deferReply({ ephemeral: false });
const embed = new EmbedBuilder().setColor('Green').setTimestamp();
let count = 0;
embed.setTitle('💻Processing Your Command');
await interaction.editReply({ embeds: [embed] });

interaction.guild.channels.cache.forEach((channel) => {
if (channel.permissionsFor(sRole)) {
console.log(
`Channel Name: ${
channel.name
} \n Permissions : ${channel.permissionsFor(sRole)}`
);

//channel.permissionOverwrites.delete(sRole.id);
//channel.permissionOverwrites.set
}
});
const role = interaction.options.getRole('role');
const sRole = interaction.options.getRole('s_role');

await interaction.deferReply({ ephemeral: false });
const embed = new EmbedBuilder().setColor('Green').setTimestamp();
let count = 0;
embed.setTitle('💻Processing Your Command');
await interaction.editReply({ embeds: [embed] });

interaction.guild.channels.cache.forEach((channel) => {
if (channel.permissionsFor(sRole)) {
console.log(
`Channel Name: ${
channel.name
} \n Permissions : ${channel.permissionsFor(sRole)}`
);

//channel.permissionOverwrites.delete(sRole.id);
//channel.permissionOverwrites.set
}
});
the log shows all channels , even if the Srole is not included additional note : my main problem is how should i filter the channels that has only a specific role in their permission list , then how do i get those permission of that role.
Squid
Squid2y ago
Instead of checking for the role's perms with channel.permissionsFor(), try checking channel.permissionOverwrites.cache.has(...)
Violet
VioletOP2y ago
thanks for your response , i appreciate it , also is it possible to get permission for that role? imma guess smth , i might be able to use
channel.permissionOverwrites.cache.get(...)
channel.permissionOverwrites.cache.get(...)
to get the permissions?
Squid
Squid2y ago
Yep! And just checking if that's undefined or not can also tell you if there's the overwrite or not
Violet
VioletOP2y ago
thats a huge help , thanks a lot 🙂 i was lost in the docs 😄 seems like .has is smth i guess TypeError: Cannot read properties of undefined (reading 'cache') [object Promise]
Squid
Squid2y ago
Can you share your code?
Violet
VioletOP2y ago
https://sourceb.in/0xM2Sx8fjH i also used
srole.id
srole.id
in case it wants the channel id. but still the same tried changing the code in some othe ways but still the same , idk whyy thou -_- cant get a straight thing about it in docs also So i was checkinh docs again I found out permissionoverwrites doesnt directly have .cache.get thing. But it will return permissionoverwritemanager Which has those properties. But how am i going to get that in return? Yeah so the code i shared i used 'sRole' and got that error and then i used 'sRole.id' which returned the same thing. Kk i was using the crash handler ill send full errro in a second turned out it working ( i did use id first time it didnt work ) i might have made a mistake but it worked and i got the channels that got that role + permission which are allowed and denied as bit numbers
Want results from more Discord servers?
Add your server