Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
How to lock and unlock an channel using discord.js v13.4

So I tried a lot of ways to locking a channel to a specific role, this is one of my attempt code:

Locking the channel

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`)

    }
});

Unlocking:

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`)

    }
});

It didn't work, also returned a error say UserResolvable is not defined I also tried this method and it still didn't work

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

According to the docs you use channel.permissionOverwrites.edit()

So your lock code would look something like this:

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
});

And then for the unlock command just change the permission values.

about 4 years ago · Juan Pablo Isaza Relatório

0

To lock use like this

channel.permissionOverwrites.edit(channel.guild.roles.everyone, {
    SEND_MESSAGES: false
}).catch((e) => { console.error(e) })
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda