Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
permission over write after channel creation, using discord.js

I'm having some issues with giving the message.author and staff permission to see the channel right after it's created, the issue is, when the channel's parent (category) is changed, it syncs the permissions of the parent (category), which disallows the user and staff to see the channel, I'm not sure how to fix this, I wish I explained well, if you have any questions, please ask.

Here is my code:

module.exports = {
  name: 'new',
  category: 'Ticket',
  description: 'Creates a new ticket.',
  aliases: ['newticket'],
  usage: 'New',
  userperms: [],
  botperms: [],
  run: async (client, message, args) => {
    if(message.author.bot) return;
    if(!message.channel.id == process.env.COMMAND_T) return;
if(!client.userTickets) {
  client.userTickets = new Map();

  const channels = message.guild.channels.cache.filter(channel => {
    if(channel) return channel.name.startsWith('t-');
    });

    if(channels) {
      for (i in Array.from(channels)) {
        client.userTickets.set(i, +i + 1);
    }
  }
}
console.log(client.userTickets)
        if(client.userTickets.has(message.author.id)) {
            return message.channel.send('<@' + message.author.id + 'You already have a ticket, please close it then run this command again!').then(m => m.delete({timeout: 10000}));
        }
        message.guild.channels.create(`t-${client.userTickets.size + 1}`, {
            permissionOverwrites: [
                {
                    id: message.author.id,
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                },
                {
                    id: process.env.ROLE_STAFF,
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                },
                {
                    id: process.env.ROLE_MEMBER,
                    deny: ['VIEW_CHANNEL']
                }
            ],
            type: 'text',
        }).then(async channel => {
            channel.setParent(process.env.TICKET_C);
            client.userTickets.set(message.author.id, client.userTickets.size + 1);
            message.channel.send(`<@` + message.author.id + `>, Done, go to your ticket! ${channel}`).then(m => m.delete({timeout: 10000}));
            client.users.cache.get(message.author.id).send(`Your ticket has been opened, go take a look: ${channel}`)
            channel.send(`Hi <@` + message.author.id + `>, Hello and welcome to your DwaCraft ticket!`);
            channel.send(`https://tenor.com/view/is-there-something-i-can-help-you-with-dan-levy-david-david-rose-schitts-creek-gif-20776045`);
            
            const logchannel = message.guild.channels.cache.find(channel => channel.id === process.env.TICKET_L);
            
            if(logchannel) {
                logchannel.send(`There was a new ticket created by <@${message.author.id}>! Channel: <#${channel.id}>`);
            }
        });
    }
}

Note: I've researched but I didn't find any answer.

Thanks for taking the time to read this.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this

message.guild.channels.create(`t-${client.userTickets.size + 1}`, {
                type: 'GUILD_TEXT',
                permissionOverwrites: [
                    {
                        id: process.env.ROLE_STAFF,
                        allow: ['VIEW_CHANNEL'],
                    },
                    {
                        id: message.author.id,
                        allow: ['VIEW_CHANNEL'],
                    },
                ],
                parent: process.env.CATEGORY
            });

This code is mine, but it is shortened, if you like the complete one send me DM

P.S I just have it for my ticket system

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!