How do i set permission override

Im trying to do
channel.permissionOverwrites.edit(roleId, { ViewChannel: false });
channel.permissionOverwrites.edit(roleId, { ViewChannel: false });
but seems like permissionOverwrites does not exist (undefined)?
13 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Luxbug
LuxbugOP8mo ago
14.15.2 i cant access permissionOverwrites on any channel type
Svitkona
Svitkona8mo ago
can you show how you defined channel
Amgelo
Amgelo8mo ago
if the error is "cannot read properties of undefined (reading permissionOverwrites)", then channel is undefined, not permissionOverwrites
Luxbug
LuxbugOP8mo ago
Nah says edit is undefined So permission override is undefined I tried all channel types idk whats the problem
TÆMBØ
TÆMBØ8mo ago
Please share the full error rather than paraphrasing it
Luxbug
LuxbugOP8mo ago
Ok…1 sec
Amgelo
Amgelo8mo ago
and also what Svitkona mentioned, how are you defining channel
Luxbug
LuxbugOP8mo ago
so its in a loop
const guild = await client.guilds.fetch("945412046072209408");

for (const channel of guild.channels.cache.values()) {
if (!channel.isTextBased()) continue;

if (!channel.manageable) continue;

channel.permissionOverwrites.edit("", { ViewChannel: false });
}
const guild = await client.guilds.fetch("945412046072209408");

for (const channel of guild.channels.cache.values()) {
if (!channel.isTextBased()) continue;

if (!channel.manageable) continue;

channel.permissionOverwrites.edit("", { ViewChannel: false });
}
Property 'permissionOverwrites' does not exist on type 'NewsChannel | StageChannel | TextChannel | PrivateThreadChannel | PublicThreadChannel<boolean> | VoiceChannel'. Property 'permissionOverwrites' does not exist on type 'PrivateThreadChannel'.
Amgelo
Amgelo8mo ago
well as the error says, private threads don't have a permission overwrites
d.js docs
d.js docs8mo ago
:method: BaseChannel#isThread @14.15.2 Indicates whether this channel is a ThreadChannel.
TÆMBØ
TÆMBØ8mo ago
Add this typeguard along with your other one to exclude threads
Luxbug
LuxbugOP8mo ago
same thing if (!channel.isThread()) continue; channel.permissionOverwrites.edit("", { ViewChannel: false }); wait sorryu ! was the problem ty for ur help
Want results from more Discord servers?
Add your server