我想将服务器中的所有频道锁定为某个角色(发送消息: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.js v12:我如何等待 DM 频道中的消息?discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 频道中的消息?)
如何让我的机器人提及发出该机器人命令的人how to make my bot mention the person who gave that bot command(如何让我的机器人提及发出该机器人命令的人)
如何修复必须使用导入来加载 ES 模块 discord.jsHow to fix Must use import to load ES Module discord.js(如何修复必须使用导入来加载 ES 模块 discord.js)
如何列出来自特定服务器的所有成员?How to list all members from a specific server?(如何列出来自特定服务器的所有成员?)
Discord bot:修复“找不到 FFMPEG"Discord bot: Fix ‘FFMPEG not found’(Discord bot:修复“找不到 FFMPEG)
使用 discord.js 加入 discord 服务器时的欢迎消息Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服务器时的欢迎消息)