Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
Discord.js 'await solo es válido en una función asíncrona' aunque sea una función asíncrona?

Estoy codificando un bot para hacer un sistema de emisión de boletos, y estoy tratando de hacer que el bot reaccione al mensaje, pero no es así, ya que recibo el error await is only valid in an async function . Sé lo que eso significa, y la parte en la que estoy confundido es que es una función asíncrona: lo sé porque antes en la función/evento, hay una declaración de await . Aquí está el código:

 client.on("message", async (message) => { if (message.author.bot) return; const filter = (m) => m.author.id === message.author.id; if (message.content === "-ticket") { let channel = message.author.dmChannel; if (!channel) channel = await message.author.createDM(); let embed = new Discord.MessageEmbed(); embed.setTitle('Open a Ticket') embed.setDescription('Thank you for reaching out to us. If you have a question, please state it below so I can connect you to a member of our support team. If you a reporting a user, please describe your report in detail below.') embed.setColor('AQUA') message.author.send(embed); channel .awaitMessages(filter, {max: 1, time: 1000 * 300, errors: ['time'] }) .then((collected) => { const msg = collected.first(); message.author.send(` >>> ✅ Thank you for reaching out to us! I have created a case for your inquiry with out support team. Expect a reply soon! ❓ Your question: ${msg} `); let claimEmbed = new Discord.MessageEmbed(); claimEmbed.setTitle('New Ticket') claimEmbed.setDescription(` New ticket created by ${message.author.tag}: ${msg} React with ✅ to claim! `) claimEmbed.setColor('AQUA') claimEmbed.setTimestamp() try{ let claimChannel = client.channels.cache.find(channel => channel.name === 'general'); claimChannel.send(claimEmbed); await claimMessage.react("✅"); } catch (err) { throw (err); } }) .catch((err) => console.log(err)); } })
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Cuando recopila los mensajes, hay una función de flecha a la que le falta una palabra clave async :

 client.on('message', async (message) => { if (message.author.bot) return; const filter = (m) => m.author.id === message.author.id; if (message.content === '-ticket') { let channel = message.author.dmChannel; if (!channel) channel = await message.author.createDM(); let embed = new Discord.MessageEmbed(); embed.setTitle('Open a Ticket'); embed.setDescription( 'Thank you for reaching out to us. If you have a question, please state it below so I can connect you to a member of our support team. If you a reporting a user, please describe your report in detail below.', ); embed.setColor('AQUA'); message.author.send(embed); channel .awaitMessages(filter, { max: 1, time: 1000 * 300, errors: ['time'] }) // it should be async .then(async (collected) => { const msg = collected.first(); message.author.send(` >>> ✅ Thank you for reaching out to us! I have created a case for your inquiry with out support team. Expect a reply soon! ❓ Your question: ${msg} `); let claimEmbed = new Discord.MessageEmbed(); claimEmbed.setTitle('New Ticket'); claimEmbed.setDescription(` New ticket created by ${message.author.tag}: ${msg} React with ✅ to claim! `); claimEmbed.setColor('AQUA'); claimEmbed.setTimestamp(); try { let claimChannel = client.channels.cache.find( (channel) => channel.name === 'general', ); claimChannel.send(claimEmbed); await claimMessage.react('✅'); } catch (err) { throw err; } }) .catch((err) => console.log(err)); } });
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda