javascript - 试图自动化频道权限,但它会更新房间中的所有角色,同时读取或写入
问题描述
我一直在努力做到这一点,以便我的不和谐服务器上的主持人角色可以使用 !host 或 !stophosting 命令来解锁或锁定他们的频道。!host 正确打开了频道备份,但 !stophosting 将除管理员之外的所有人锁定在频道之外。我希望主机仍然可以访问它。
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const fs = require('fs');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.content.includes(`${prefix}stophosting`)) {
let channel = message.channel;
let roles = message.guild.roles; // collection
const memberRole = message.guild.roles.cache.find(r => r.name === 'member');
const defaultRole = message.guild.roles.cache.find(r => r.name === 'default');
const hostRole = message.guild.roles.cache.find(r => r.name === 'Host');
channel.overwritePermissions([
{
id: defaultRole.id,
deny: ['VIEW_CHANNEL'],
},
], 'Lockdown')
channel.overwritePermissions([
{
id: memberRole.id,
deny: ['VIEW_CHANNEL'],
},
], 'Lockdown')
channel.overwritePermissions([
{
id: hostRole.id,
allow: ['VIEW_CHANNEL'],
},
], 'Lockdown')
.then(console.log)
.catch(console.log);
}
});
client.login(token);
解决方案
推荐阅读
- azure - 认知服务(LUIS、QnA maker)未从 vNet 访问
- javascript - 从 node_module @zilliqa-js/util 导入打字稿文件失败
- r - 如何将excel类型文件转换为html类型文件?
- ios - iOS Firebase 令牌获取问题
- javascript - JS 是否有一种简单的方法来格式化输入类型,同时提示 1,000.00
- linux - 避免在 shell 脚本中使用单独的文件
- java - 如何访问多维数组中的特定索引?
- java - Jooq - 间隔 2 周
- java - 无法以我需要的格式将日期字符串转换为日期对象
- reactjs - 当我传递给 axios 发布请求时使用 setState 更新数据