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

180
Views
Asíncrono en una condición if (JavaScript v13)

Quiero usar la palabra clave await en una declaración if pero dice:

 await message.guild.channels.create("tickets", { ^^^^^ SyntaxError: await is only valid in async functions and the top level bodies of modules
 if (message.content.startsWith("n!ticket setup")) { let channel = message.mentions.channels.first() let kate; let modrole = message.mentions.roles; message.guild.channels.cache.forEach(chn => { if (chn.type == "GUILD_CATEGORY" && !kate && chn.name.toLowerCase() == "tickets ") { kate = chn; } }) if (!channel) return message.channel.send({ content: "Du musst einen Kanal angeben wo die Nachricht reingesendet werden soll." }); if (!kate) { await message.guild.channels.create("tickets", { type: "GUILD_CATEGORY", permissionOverwrites: [{ id: message.guild.id, deny: ["VIEW_CHANNEL"] }, { id: bot.user.id, allow: ["VIEW_CHANNEL"] } ] }).then(l => kate = l); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cambie su código a algo como a continuación, envuelva todo en una función async . Tiene que envolver su código if en alguna función async para que funcione

 async function foo(){ let channels=message.guild.channels.cache for(let i=0;i<channels.length;i++){ if(channels[i].type == "GUILD_CATEGORY" && !kate && channels[i].name.toLowerCase() == "tickets "){ kate = channels[i]; } }) if(!channel) return message.channel.send({content: "Du musst einen Kanal angeben wo die Nachricht reingesendet werden soll."}); if(!kate){ await message.guild.channels.create("tickets", { type:"GUILD_CATEGORY", permissionOverwrites:[ {id:message.guild.id, deny:["VIEW_CHANNEL"]}, {id:bot.user.id,allow:["VIEW_CHANNEL"]} ] }).then(l=>kate=l); }``` }

O puede ser que pueda crear una versión asíncrona de forEach a partir del ejemplo Ver esto

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!