-1

I'm trying to script a Ticket System. I sucessfully can create a ticket but i don't know how to close it (delete it) i tried looking up stuff but i couldn't find a solution for my code.

My Code:


        case 'ticket':
        case 'Ticket':

            var guild = client.guilds.cache.get('877207084251369512')
            guild.channels.create(message.author.username + '-ticket', {
                type: 'text',
                topic: 'Ticket' + message.author.id,
                parent: '896402801428456046',
                permissionOverwrites: [
                    {
                     id: message.author.id,
                     allow: ['SEND_MESSAGES', 'VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'EMBED_LINKS', 'ATTACH_FILES'],
                    },
                    {
                     id: message.guild.roles.everyone,
                     deny: ['VIEW_CHANNEL'],
                    },
                {
                     id: "877570054710001735",
                     allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                    },
                   ],
                  })

            let created = new Discord.MessageEmbed()
            .setTitle("Ticket-System")
            .setDescription("You're Ticket was created!")
            .setTimestamp()
            .setFooter('Ticket System')
            .setColor("GREY")
            
            
            message.channel.send({embeds: [created]});
            
            let channel = message.guild.channels.cache.find(channel => channel.name === `${message.author.username}-ticket`);
            message.guild.channels.cache.get(`${channel}`)
I need Help
  • 204
  • 3
  • 13
  • 1
    For the first part it’s `username-ticket` but the second part is `ticket-username` – MrMythical Oct 12 '21 at 21:16
  • Tip: if you lowercase the argument you're switching you'll only need to have a lowercased case value and not have to worry about other variations of letter casing – Elitezen Oct 12 '21 at 21:36

2 Answers2

0

In here

guild.channels.create(message.author.username + '-ticket', {

You used <someusername>-ticket and in

.find(channel => channel.name === `ticket-${message.author.username}`);

You used ticket-<someusername>

Either choose to put ticket-<someusername> in both of your lines or <someusername>-ticket

PS : I recommend you using IDs instead of usernames since you know the id has only numbers when usernames can have special and annoying characters. Also to fix some potential issues you can change channel to channel.id

message.guild.channels.cache.get(`${channel.id}`)
MrMythical
  • 8,908
  • 2
  • 17
  • 45
Staxlinou
  • 1,351
  • 1
  • 5
  • 20
  • Thanks i changed the mistake with the ` `ticket-${message.author.username}` ` I still got the problem with deleting the channel – I need Help Oct 13 '21 at 13:20
0

There will be special symbols in the channel name. You can use the following program to delete special symbols and blanks

const channelname1 = removeSpaces(`${message.author.username}`)
const channelname = channelname1.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');

Delete channel Then I’m not sure how you want to delete the channel, I can only give you a way to delete the channel

channel.delete();

In addition, I suggest you can delay 0.5 seconds when defining the channel

ben1020
  • 102
  • 1
  • 2
  • 7
  • I tried to delete the channel like this, you can see my code for that [here](https://stackoverflow.com/questions/69575084/deleting-a-specific-channel-discord-js-v-13?noredirect=1#comment122976929_69575084) but it's not working – I need Help Oct 21 '21 at 17:01