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)); } })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)); } });