首页 > 解决方案 > 试图自动化频道权限,但它会更新房间中的所有角色,同时读取或写入

问题描述

我一直在努力做到这一点,以便我的不和谐服务器上的主持人角色可以使用 !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);

标签: javascriptdiscord.js

解决方案


推荐阅读