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

337
Views
¿Cómo hacer que le dé a cada boleto un número único?, Discord.js

Cómo funciona:

Estoy tratando de hacer que si alguien reacciona al mensaje que envía un miembro del personal, se abre un ticket.

El problema:

Quería usar la identificación del miembro, pero es demasiado grande. Traté de usar el nombre del jugador, no lo encuentra como canal por alguna razón, ¿quizás un número único es mejor?

Estoy usando un sistema de manejo de comandos, por lo que no verá ninguna de las cosas básicas (por ejemplo client.login )

Aquí está mi código:

 const { Discord } = require('discord.js'); const axios = require("axios") module.exports = { name: 'thing', category: 'Owner', aliases: ["t"], description: 'thing command.', usage: 'thing', userperms: [], botperms: [], run: async (client, message, args) => { message.channel.send('Click "⚔" to open a ticket!').then(function(message) { message.react('⚔'); const filter = (reaction, user) => { return ['⚔'].includes(reaction.emoji.name) && user.id === message.author.id; }}); client.on('messageReactionAdd', (reaction, ruser) => { if (!ruser.bot) { if (reaction.emoji.name == '⚔') { if(message.guild.channels.cache.find(channel => channel.name == (`t-${ruser.id}`))) { return message.channel.send('<@' + ruser.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-${ruser.id}`, { permissionOverwrites: [ { id: message.author.id, allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'], }, { id: message.guild.roles.everyone, deny: ['VIEW_CHANNEL'], }, ], type: 'text', }).then(async channel => { message.channel.send(`<@` + ruser.id + `>, you have successfully created a ticket! Please click on ${channel} to view your ticket.`) .then(m => m.delete({timeout: 3000})); channel.send(`Hi <@` + ruser.id + `>, welcome to your ticket! Please be patient, we will be with you shortly.`); const logchannel = message.guild.channels.cache.find(channel => channel.name === 'server-logs'); if(logchannel) { logchannel.send(`Ticket-${ruser.username} created. Click the following to veiw <#${channel.id}>`); } }); } }}); }}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hay múltiples formas de hacer esto. Crearía un objeto <Map> cuyas claves deberían representar la identificación del usuario y valores la identificación del ticket que pertenece a ese usuario. También declararía un ticketID variable que se incrementaría en 1 cada vez que se creara un nuevo ticket. En cada reacción, el bot debe verificar si la ID de usuario es una clave existente del mapa y, de no ser así, debe crear una nueva entrada en él:

 (...) let ticketCounter = 0; const userTickets = new Map(); client.on('messageReactionAdd', (reaction, ruser) => { if(!ruser.bot) { if(reaction.emoji.name == '⚔') { if(userTickets.has(ruser.id)) { return message.channel.send('<@' + ruser.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: message.guild.roles.everyone, deny: ['VIEW_CHANNEL'], }, ], type: 'text', }).then(async channel => { userTickets.set(ruser.id, ticketCounter++); // This will create the map entry whose value is the previous ticketCounter value, the ++ increments afterwards. message.channel.send(`<@` + ruser.id + `>, you have successfully created a ticket! Please click on ${channel} to view your ticket.`).then(m => m.delete({timeout: 3000})); channel.send(`Hi <@` + ruser.id + `>, welcome to your ticket! Please be patient, we will be with you shortly.`); const logchannel = message.guild.channels.cache.find(channel => channel.name === 'server-logs'); if(logchannel) { logchannel.send(`Ticket-${ruser.username} created. Click the following to veiw <#${channel.id}>`); } }); } } });
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!