Discord.js V12如何锁定某个角色的所有频道?
Discord.js V12 How can I lock all channels for a certain role?
我想将服务器中的所有频道锁定到某个角色(发送消息:false)
这是我当前的代码,我得到的错误是 TypeError [INVALID_TYPE]: Supplied overwrites is not an Array or Collection of Permission Overwrites.
代码:
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
overwritePermissions 将替换频道中的权限覆盖,这意味着如果频道之前有权限覆盖,它将全部替换。
在那种情况下 ->
message.channel.overwritePermissions([
{
id: muteRole.id,
deny: ['SEND_MESSAGES'],
},
], 'Needed to change permissions');
createOverwrite 将覆盖此频道中用户或角色的权限。 (如果存在则替换)
在那->
message.channel.createOverwrite(muteRole, {
SEND_MESSAGES: false
})
}
修改所有频道的权限->
message.guild.channels.cache.forEach(ch =>
{
if(ch.type == "text")
ch.overwritePermissions([
{
id: muteRole.id,
deny: ['SEND_MESSAGES'],
},
], 'Needed to change permissions');
})
我想将服务器中的所有频道锁定到某个角色(发送消息:false)
这是我当前的代码,我得到的错误是 TypeError [INVALID_TYPE]: Supplied overwrites is not an Array or Collection of Permission Overwrites.
代码:
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
overwritePermissions 将替换频道中的权限覆盖,这意味着如果频道之前有权限覆盖,它将全部替换。
在那种情况下 ->
message.channel.overwritePermissions([
{
id: muteRole.id,
deny: ['SEND_MESSAGES'],
},
], 'Needed to change permissions');
createOverwrite 将覆盖此频道中用户或角色的权限。 (如果存在则替换)
在那->
message.channel.createOverwrite(muteRole, {
SEND_MESSAGES: false
})
}
修改所有频道的权限->
message.guild.channels.cache.forEach(ch =>
{
if(ch.type == "text")
ch.overwritePermissions([
{
id: muteRole.id,
deny: ['SEND_MESSAGES'],
},
], 'Needed to change permissions');
})