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

169
Vistas
Discord.js 'await is only valid in an async function' even though it is an async function?

I am coding a bot to make a ticketing system, and I am trying to get the bot to react to the message, but it isn't as I am getting the error await is only valid in an async function. I know what that means, and the part where I am confused is that it is an async function: I know this because earlier in the function/event, there is an await statement. Here is the code:

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

When you collect the messages, there is an arrow function that has a missing async keyword:

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