DISCORD TEXT CHANNEL RELAY UPDATE

Asked

Viewed 321 times

-2

Good Afternoon.

I’m making a BOT for Discord, and I want to create a text channel and then manage the permissions of it.

However, when updating permissions, you are not updating. I already guaranteed that the BOT is as ADM server.

Follows code:

const Discord = require("discord.js")
exports.run = async (client, message, args, db, civs) => {
const content = args.join(" ");
message.delete();


//if (!message.guild.me.hasPermission('MANAGE_CHANNELS')) return message.channel.send('Não tenho permissão de gerenciar canais')
//if (message.guild.channels.cache.find(ch => ch.name.includes(message.author.id))) return message.reply('Já existe um canal criado pra você ')

if (!args[0]) {
    return message.channel.send(`<@${message.author.id}>, escreva a denúncia após o comando`);
  } else if (content.length > 1000) {
    return message.channel.send(`<@${message.author.id}>, forneça uma denúncia de no máximo 1000 caracteres. Caso precise de mais caracteres, continue escrevendo depois de fazer a denúncia primária.`);
  } else {


let channel // declarando variavel global channel que é o canal que vai ser criado e marcado a pessoa que deu comando
try { // ← Tentar criar o canal, se nao conseguir cai no catch
    channel = await message.guild.channels
        .create(`den•┋${message.member.displayName}|`,{
            type: 'text',
            permissionOverwrites: [
                {
                 id: '729790119388905552', // everyone
                 deny: ['VIEW_CHANNEL'], // permissoes de nao ver o canal (ler mensagens)
            },
            {
                  id: message.author.id, // permissoes para quem digitou o comando
                  allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'], // essa pessoa pode ver o canal e enviar mensagens
            },
            {
                  id: '740149831825358848',  // Moderador
                  allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'] // essa pessoa pode ver o canal e enviar mensagens
            },
            ],
        });
        channel.setParent('774700250953940992');         
    }
catch(err) {
    message.channel.send('Erro: ' + err.message);
}

    let timeout = await channel.send(`<@${message.author.id}>`);// espera o canal ser criado e marca o membro

    // Envia conteúdo da mensagem no canal criado.
    const msg = await channel.send(
       new Discord.MessageEmbed()
       .setColor("#FFFFF1")
       .addField("Autor:", message.author)
       .addField("Conteúdo", content)
       .setFooter("ID do Autor: " + message.author.id)
       .setTimestamp()
     );
}}

exports.config = {
name: 'denuncia',
aliases: ['denuncia']
}

Basically, I want only the author and moderators to be able to see this text channel. Any suggestions?

2 answers

-2

I’m not sure if this is what you’re looking for, but despite trying to create a channel within a Try/catch I think when you create the channel with the await message.guild.chanels.create() have to assign permissions after the channel is created and not at the time it is created, a solution for this is to add a .then and a .catch() to the object Channel

But I’m not sure if the code I’m going to post below will work because I’ve never tried to create channels as a way to report users. A channel is usually created in the server administration category where the BOT sends all the ports that are made and no independent channel is created for each report. But I will leave the two references where I drew this conclusion at the end of the answer, another good option is to always consult the official documentation of Discord.js here, I know that sometimes it can seem a bit confusing but just research the methods we want to apply in the search bar, usually these say everything that such a method is able to create and how to use it.

let channel; // declarando variavel global channel que é o canal que vai ser criado e marcado a pessoa que deu comando
channel = await message.guild.channels
  .create(`den•┋${message.member.displayName}|`, {
    type: "text",
  })
  .then((channel) => {
    channel.setParent("774700250953940992");
    channel.permissionOverwrites([
      {
        id: "729790119388905552", // everyone
        deny: ["VIEW_CHANNEL"], // permissoes de nao ver o canal (ler mensagens)
      },
      {
        id: message.author.id, // permissoes para quem digitou o comando
        allow: ["VIEW_CHANNEL", "SEND_MESSAGES"], // essa pessoa pode ver o canal e enviar mensagens
      },
      {
        id: "740149831825358848", // Moderador
        allow: ["VIEW_CHANNEL", "SEND_MESSAGES"], // essa pessoa pode ver o canal e enviar mensagens
      },
    ]);
  })
  .catch((err) => console.log(err));

Other links that may help: Youtube video showing how to create channels with Discord.js v12 (Personally I used the playlist of this creator to create my Bot, but can always exist better ways)

I hope it helps

  • That’s not exactly it. The problem is in setting the restriction to @Everyone.

  • Have you tried instead of restricting access to @Everyone in a global way, use the built-in permissions in Discord.js to create a channel that only people with permission MANAGE_GUILD, for example, can you see? The Discord permissions serve to facilitate this type of situation, as you should not use a statement (@Everyone) that literally encompasses all server users included administrators, in fact my answer is not the right one but you should use the built-in Discord permissions for this sort of thing as the documentation says

-2


I managed to solve the problem.

It turns out that using Everyone ID was not effective. So, I found a way out, which is:

const cargo_todos = message.guild.roles.cache.find((cargo_todos) => {
    return cargo_todos.name === '@everyone'
})

let channel // declarando variavel global channel que é o canal que vai ser criado e marcado a pessoa que deu comando
try { // ← Tentar criar o canal, se nao conseguir cai no catch
    channel = await message.guild.channels
        .create(`den•┋${message.member.displayName}|`,{
            type: 'text',
            parent: '774683424551600178',
            permissionOverwrites: [
            {
                 id: cargo_todos.id, // Everyone
                 deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
            },

With this, the BOT worked correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.