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.