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');
})
相关文章