問題描述
我想將服務(wù)器中的所有頻道鎖定為某個角色(發(fā)送消息:false)這是我當(dāng)前的代碼,我得到的錯誤是 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 將替換頻道中的權(quán)限覆蓋,這意味著如果頻道之前有權(quán)限覆蓋,它將全部替換.
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 將覆蓋權(quán)限對于此頻道中的用戶或角色.(如果存在則替換)
createOverwrite will Overwrite the permissions for a user or role in this channel. (replaces if existent)
在那個->
message.channel.createOverwrite(muteRole, {
SEND_MESSAGES: false
})
}
修改所有頻道的權(quán)限 ->
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');
})
這篇關(guān)于Discord.js V12 如何鎖定某個角色的所有頻道?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!