Skip to content
Advertisement

discord.js setting permission on channel to “/” (neutral)

I am looking to set user permissions on a text channel to neutral/null/”/” but overwritePermissions() seems to only use allow and deny currently, a past post I saw showed setting the value to null but allow/deny seems to prevent that.

I am setting permissions on a text channel like this:

member.guild.channels.cache.array().forEach((channel) => {
 channel.overwritePermissions([
  {
   id: member,
   deny: ['VIEW_CHANNEL'],
  },
 ]);
});

and would like to effectively undo this action, changing the [‘VIEW_CHANNEL’] permission to allow overrides other permissions in the server and does not work for my case.

overwritePermissions() documentation

Advertisement

Answer

I believe what you are looking for is Channel#updateOverwrites() which, as well as having a different function to overwritePermissions(), also has a different format.

overwritePermissions overwrites all the permissions in a channel (as suggested by its name). So even if you only want to change one thing, overwritePermissions will bring everything with it. Thankfully, we also have updateOverwrites. This method will only change permissions for one member/role.

Here’s how you could use it:

// as a note, `forEach()` automatically coverts the collection to an array,
// so no need for the `array()` function
member.guild.channels.cache.forEach((channel) => {
 channel.updateOverwrite(member, { // update permissions only for the member
  VIEW_CHANNEL: null, // set view_channel to default
 });
});
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement