granting authorization to modify content post channel establishment in discord using discord.js

I am encountering an issue with granting the message.author and staff permission to view the channel right after its creation. The problem arises when the channel's parent (category) is changed, causing it to synchronize with the permissions of the parent category, thereby preventing the user and staff from accessing the channel. I am unsure how to resolve this issue and hope that I have explained it clearly. If you have any questions, please feel free to ask.

Below is the code snippet:

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

Please note that despite researching extensively, I could not find a solution to this problem.

Thank you for taking the time to read through this.

Answer №1

Give this a try

Create a new channel with the name `t-${client.userTickets.size + 1}` in the server, set to GUILD_TEXT type, and with specific permission overwrites for staff and the message author. The new channel will be placed under a designated category.

This code snippet is my own creation but has been shortened here. If you would like the full version, feel free to send me a direct message.

Just a note - I use this code for my ticket system only.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Finding a specific object within an array of objects by searching through a key value pair

In my collection, I have an array of objects structured as follows: [{ "businessunit": [{ "Area": [{ "Asset": [{ "Wells": { "Well": "Well 11" }, "name": "Field ...

Surprising "unexpected end of line" JavaScript lint notification out of nowhere

In this simplified version of my JavaScript code: function addContent() { var content = []; content.append( makeVal({ value : 1 }) ); // lint message generated } After running a lint program, I received the followi ...

Having trouble with the functionality of a simple jQuery toggle menu on mobile?

I am experiencing an issue with a simple toggle menu that utilizes jQuery's on: tap feature, but it is not functioning as expected: <nav id="mobile-nav"> <ul> <li>Item 1</li> <li>Item 2</li> ...

Creating visually appealing website designs with Firefox by implementing smooth background image transitions using Javascript with

Currently, I am facing an issue with the banner area on my website. The background of the banner is set to change every 10 seconds using JavaScript. However, there seems to be a flickering effect that occurs for a brief moment when the background-image is ...

Diminishing sheets in the realm of C# web application development

I have been researching ways to incorporate a fading page function, but I am encountering some issues. I am unsure about the specific code that needs to be included in jquery.js and how to integrate this script into all of my web forms or alternatively int ...

Exploring the Touch Feature in Angular

I am facing an issue with touch events as I am not receiving any useful X/Y coordinates. The event object does not provide the necessary information I need for touch events (https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/changedTouches). Despi ...

Error: Cloudant encountered a problem processing your request

Why is my attempt to upload JSON objects into a Cloudant database resulting in a "400 bad request" error? pos = { 'lat': position.coords.latitude, 'long' : position.coords.longitude }; $.ajax({ type: "POST", ...

Redirecting to an Unverified Website

I encountered an issue in my service.ts file where VeraCode code scan is failing Flaws by CWE ID: URL Redirection to Untrusted Site ('Open Redirect') (CWE ID 601)(16 flaws) Description The web application is vulnerable to URL redirection attacks ...

The user model cannot be assigned to the parameter of type Document or null in a mongoose with Typescript environment

While working with Typescript, I encountered an error related to mongoose. The issue arises from the fact that mongoose expects a promise of a mongoose document (in this case, the user's document) or "null" to be resolved during a search operation. Ho ...

express routes are failing to execute the function

When I navigate to routes in my browser, the results are displayed in my console but the server call seems to be running for a long time in the network. Can anyone provide some assistance? My controller, var express = require('express'); var ...

updating a div with URL redirection instead of global redirect

I am facing an issue with redirecting my website flow to the login page when a user clicks any link on the page after the session has expired (either due to timeout or manual logout from another window). In an attempt to solve this, I inserted the followi ...

Unable to execute Protractor using Node.js command line

Hi there! Currently, I am in the process of setting up protractor for the very first time using Node.js. I found detailed instructions on how to do this on the AngularJS website under the section "Running E2E Tests": https://docs.angularjs.org/tutorial Ho ...

Linkyfy.js does not function correctly with each and not statements

Trying to incorporate a linkifying script on a website, which transforms URLs in text into clickable links. Utilizing the following solution: https://github.com/SoapBox/linkifyjs To make it operational (post-download), the following steps are required: & ...

What is the best way to retrieve the content of HTML tags from a string using JavaScript or AngularJS?

I have a string with mixed content of HTML tags and text. Here is an example: var str = "<p></p><p><i>blabla</i></p><p><i><b>blaaaaaablaaaaa</b></i></p><iframe src="..." height=" ...

Utilize ng-repeat to iterate over two arrays

Two arrays are at my disposal here. The first array contains option content, while the second array consists of option tags (i.e., A, B, C, D). How can I structure the layout for the 'input type="radio"' using ng-repeat? To start off, I am attem ...

Having trouble uploading several files with Multer functionality?

I've encountered an issue with Multer in Node.js where I can't seem to select and upload multiple files. In a previous exercise, I had no trouble uploading a single file, but now I'm struggling with enabling multiple uploads. What am I mis ...

What does the typeof keyword return when used with a variable in Typescript?

In TypeScript, a class can be defined as shown below: class Sup { static member: any; static log() { console.log('sup'); } } If you write the following code: let x = Sup; Why does the type of x show up as typeof Sup (hig ...

What is preventing the input box from shrinking further?

I created a search box using CSS grid that is supposed to shrink when the page is resized. However, it doesn't seem to shrink as much as I expected it to. Here is how it appears when fully extended: https://i.stack.imgur.com/tPuCg.png And here is how ...

Error encountered: Unable to access the 'Lastname' property as it is undefined

Even though the console displays the value of $("#surname").val(), I am still encountering an error. Could it be that the script is executing before the form is dynamically built? $(function () { $("#addEmployeForm").submit(function (event) { ...

Incorporate a personalized add-button into the material-table interface

My current setup includes a basic material-table structured like this: <MaterialTable options={myOptions} title="MyTitle" columns={state.columns} data={state.data} tableRef={tableRef} // Not functioning properly editabl ...