Lo estoy haciendo para que si un miembro dice ~nuevo, crea un nuevo boleto para él, pero el problema es que el nombre del canal tiene que ir en un número único, como t-1, luego t-2, etc.
Pero se queda solo con "t-1", para ser claros, estoy usando un controlador de comandos.
aquí está mi código:
module.exports = { name: 'new', category: 'Ticket', description: 'Creates a new ticket.', aliases: ['newticket'], usage: 'new', userperms: [], botperms: [], run: async (client, message, args) => { let ticketCounter = 1; const userTickets = new Map() if(userTickets.has(message.author.tag)) { return message.channel.send('<@' + message.author.id + '> you already have a ticket, please close your existing ticket first before opening a new one!').then(m => m.delete({timeout: 3000})); } message.guild.channels.create(`t-${ticketCounter}`, { permissionOverwrites: [ { id: message.author.id, allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'], }, { id: "916785912267034674", allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'], }, { id: message.guild.roles.everyone, deny: ['VIEW_CHANNEL'], }, ], type: 'text', }).then(async channel => { channel.setParent('916778691672031293'); userTickets.set(message.author.id, ticketCounter++); message.channel.send(`<@` + message.author.id + `>, you have successfully created a ticket! Please click on ${channel} to view your ticket.`).then(m => m.delete({timeout: 3000})); channel.send(`Hi <@` + message.author.id + `>, welcome to your ticket! Please be patient, we will be with you shortly.`); const logchannel = message.guild.channels.cache.find(channel => channel.name === 'test'); if(logchannel) { logchannel.send(`Ticket-${ticketCounter} created. Click the following to veiw <#${channel.id}>`); } }); } }¡Gracias!
Use <Map>.size en lugar de un incrementador ya que el código se vuelve a ejecutar después de cada comando, el contador se establecerá en 1 cada vez.
if(!client.userTickets) client.userTickets = new Map(); client.userTickets.set(message.author.id, client.userTickets.size + 1); message.guild.channels.create(`t-${client.userTickets.size + 1}`, { ... });Ejemplo para su código:
module.exports = { name: 'new', category: 'Ticket', description: 'Creates a new ticket.', aliases: ['newticket'], usage: 'new', userperms: [], botperms: [], run: async (client, message, args) => { if(!client.userTickets) client.userTickets = new Map() if(client.userTickets.has(message.author.id)) { return message.channel.send('<@' + message.author.id + '> you already have a ticket, please close your existing ticket first before opening a new one!').then(m => m.delete({timeout: 3000})); } message.guild.channels.create(`t-${client.userTickets.size + 1}`, { permissionOverwrites: [ { id: message.author.id, allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'], }, { id: "916785912267034674", allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'], }, { id: message.guild.roles.everyone, deny: ['VIEW_CHANNEL'], }, ], type: 'text', }).then(async channel => { channel.setParent('916778691672031293'); client.userTickets.set(message.author.id, client.userTickets.size + 1); message.channel.send(`<@` + message.author.id + `>, you have successfully created a ticket! Please click on ${channel} to view your ticket.`).then(m => m.delete({timeout: 3000})); channel.send(`Hi <@` + message.author.id + `>, welcome to your ticket! Please be patient, we will be with you shortly.`); const logchannel = message.guild.channels.cache.find(channel => channel.name === 'test'); if(logchannel) { logchannel.send(`Ticket-${client.userTickets.size} created. Click the following to veiw <#${channel.id}>`); } }); } }