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

113
Views
Cómo obtener el valor de una variable fuera del alcance de la función de flecha que la creó

Entonces, tengo este código:

 client.on("messageCreate", async (msg) => { if (msg.content.startsWith("-p")) { if (!msg.member.voice?.channel) return msg.channel.send("Por favor..."); const connection = joinVoiceChannel({ channelId: msg.member.voice.channel.id, guildId: msg.guild.id, adapterCreator: msg.guild.voiceAdapterCreator, }); google .youtube("v3") .search.list({ key: process.env.YOUTUBE_TOKEN, part: "id", q: msg.content.slice(3), maxResults: 1, }) .then((response) => { const { data } = response; let link = "https://www.youtube.com/watch?v=" + data.items.id.videoId; }); let args = msg.content.slice(3); let stream = await play.stream(args); let resource = createAudioResource(stream.stream, { inputType: stream.type, }); let player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Play, }, }); player.play(resource); connection.subscribe(player); } });

Y me gustaría usar el valor de la variable "enlace", que es una cadena, como parámetro para el método play.stre(args)

No entiendo completamente cómo hacer eso

Además, si es posible, me gustaría encontrar una manera de almacenar ese valor también dentro de una matriz fuera del todo:

 *client.on('messageCreate' , async msg => {... ...})*
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Lo más probable es que desee llamar then play.stream desde dentro de la devolución de llamada de la list :

 google.youtube("v3") .search.list({ key: process.env.YOUTUBE_TOKEN, part: "id", q: msg.content.slice(3), maxResults: 1, }) .then(async (response) => { const { data } = response; let link = "https://www.youtube.com/watch?v=" + data.items.id.videoId; let stream = await play.stream(link); });

De esta manera, se asegurará de tener un valor establecido para link cuando lo use para llamar a stream .

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!