Discord.js V12 如何锁定某个角色的所有频道?

时间:2023-02-10
本文介绍了Discord.js V12 如何锁定某个角色的所有频道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将服务器中的所有频道锁定为某个角色(发送消息:false)这是我当前的代码,我得到的错误是 TypeError [INVALID_TYPE]: Supplied overwrites is not an Array or Collection of Permission Overwrites.代码:

I want to lock all channels in the server to a certain role (Send messages: false) This is my current code, the error I get is TypeError [INVALID_TYPE]: Supplied overwrites is not an Array or Collection of Permission Overwrites. Code:

client.on('message', async message => {
    if(message.content.startsWith(prefix + "modrek")) {
        let muteRole = message.guild.roles.cache.find(role => role.name == "Mute")
        const channels = message.guild.channels.cache.filter(ch => ch.type !== "category")
        
        message.guild.channels.forEach(ch => 
            {
            if(ch.type == "text")
              ch.overwritePermissions([
              {
                 id: muteRole.id,
                 deny: ['SEND_MESSAGES'],
              },
            ], 'Needed to change permissions');
            }) 
    
    }

})

如果有人可以帮助我,请告诉我:D

Let me know if someone can help me out :D

推荐答案

overwritePermissions 将替换频道中的权限覆盖,这意味着如果频道之前有权限覆盖,它将全部替换.

overwritePermissions will replace the permission overwrites in the channel that means if the channel had previous permission overwrites it will replace them all.

在那种情况下->

In that case ->

message.channel.overwritePermissions([
  {
     id: muteRole.id,
     deny: ['SEND_MESSAGES'],
  },
], 'Needed to change permissions');

createOverwrite 将覆盖权限对于此频道中的用户或角色.(如果存在则替换)

createOverwrite will Overwrite the permissions for a user or role in this channel. (replaces if existent)

在那个->

message.channel.createOverwrite(muteRole, {
            SEND_MESSAGES: false
    })
    }

修改所有频道的权限 ->

Modify permissions for all channels ->

message.guild.channels.cache.forEach(ch => 
{
if(ch.type == "text")
  ch.overwritePermissions([
  {
     id: muteRole.id,
     deny: ['SEND_MESSAGES'],
  },
], 'Needed to change permissions');
}) 

这篇关于Discord.js V12 如何锁定某个角色的所有频道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:服务器问候语 下一篇:Discord 客户端对象在导出后未定义

相关文章

最新文章