Andryxa
Andryxa

Reputation: 113

How do I remove the rights to view the channel from the team author? Discord.js

I want to make a team !test.

Those who use this command are taken away the rights to view the channel #channel_test

My code:

client.on("message", async (message) => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;
  const args = message.content.slice(prefix.length).trim().split(" ");
  const command = args.shift().toLowerCase();
  let discussionChannel = client.channels.cache.get("808068114981978152");

  if (message.member.roles.cache.has("838776329176088586")) {
    if (command === "test") {
      discussionChannel.rolePermissions('838776329176088586').remove('VIEW_CHANNEL: true')
      discussionChannel.updateOverwrite(message.member, { VIEW_CHANNEL: false })
      client.channels.cache.get("776012673879244840").send("Good")
    }
  }
});

Upvotes: 0

Views: 119

Answers (1)

PerplexingParadox
PerplexingParadox

Reputation: 1196

You only have to slightly change the method you are using rolePermissions (which actually doesn't exist), with the updateOverwrite method instead.

Assuming that discussionChannel is a TextChannel object, then you can simply replace your statement of:

discussionChannel.rolePermissions('838776329176088586').remove('VIEW_CHANNEL: true')

with this:

discussionChannel.updateOverwrite(message.member, { VIEW_CHANNEL: false });

For more information regarding writing permissions for channels, feel free to check the Discord.js Guide.

Upvotes: 1

Related Questions