【问题标题】:How to lock and unlock an channel using discord.js v13.4如何使用 discord.js v13.4 锁定和解锁频道
【发布时间】:2022-01-12 01:12:13
【问题描述】:

所以我尝试了很多方法将频道锁定为特定角色,这是我的尝试代码之一:

锁定频道

const Command = require("../structures/Command.js");
const { Permissions } = require('discord.js');

module.exports = new Command({
    name: "lock",
    description: "lock the channel that the command is executed",

    async run(message, args, client) {
        if (message.author.bot) return;
        if (message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)){
            let role = message.guild.roles.cache(r => r.id === "895151537511362600");
            role.overwritePermissions(UserResolvable, {
    VIEW_CHANNEL: true,
    SEND_MESSAGES: false,
    READ_MESSAGE_HISTORY: true,
    ATTACH_FILES: false
});            
        } else message.reply(`why do you want to use a mod command when you're not a mod`)

    }
});

解锁:

const Command = require("../structures/Command.js");
const { Permissions } = require('discord.js');

module.exports = new Command({
    name: "unlock",
    description: "unlock the channel that the command is executed",

    async run(message, args, client) {
        if (message.author.bot) return;
        if (message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)){
            let role = message.guild.roles.cache(r => r.id === "895151537511362600");
            role.overwritePermissions(UserResolvable, {
    VIEW_CHANNEL: true,
    SEND_MESSAGES: true,
    READ_MESSAGE_HISTORY: true,
    ATTACH_FILES: true
});            
        } else message.reply(`why do you want to use a mod command when you're not a mod`)

    }
});

它不起作用,还返回一个错误说UserResolvable is not defined 我也试过this method 还是不行

【问题讨论】:

  • 您链接的问题的答案是“//传递 'UserResolvable' 类型的东西,如 Wiki 中所述!”换句话说,将其替换为用户可解析的

标签: javascript discord.js


【解决方案1】:

根据你使用的docs channel.permissionOverwrites.edit()

所以你的锁码看起来像这样:

message.channel.permissionOverwrites.edit(message.guild.everyone.id, {
    VIEW_CHANNEL: false,
    SEND_MESSAGES: false,
    READ_MESSAGE_HISTORY: false,
    ATTACH_FILES: false
});

message.channel.permissionOverwrites.edit("ROLE_ID", {
    VIEW_CHANNEL: true,
    SEND_MESSAGES: true,
    READ_MESSAGE_HISTORY: true,
    ATTACH_FILES: true
});

然后对于解锁命令只需更改权限值。

【讨论】:

  • message.guild.everyone.id?你是说message.guild.id 还是message.guild.roles.everyone.id? (反正它们都是一样的)
【解决方案2】:

像这样锁定使用

channel.permissionOverwrites.edit(channel.guild.roles.everyone, {
    SEND_MESSAGES: false
}).catch((e) => { console.error(e) })

【讨论】:

  • 我只是想把它锁定到某个角色,而不是@所有人角色
猜你喜欢
  • 2022-01-24
  • 1970-01-01
  • 2021-12-11
  • 2020-10-30
  • 1970-01-01
  • 1970-01-01
  • 2016-09-26
  • 1970-01-01
相关资源
最近更新 更多