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

181
Views
¿Cómo arreglar "catch faltante o finalmente después de intentarlo" si ya puse catch?

Aquí está mi código

 const {getAudioUrl} = require("google-tts-api") const langlist = ["en", "id"] let language = args[0] if(langlist.find(c => c === language)) { if(!language) return message.reply("Please enter the language") if(!args[1]) return message.reply("Please enter the text") const text = args.slice(1).join(" ") if(text.length > 200) return message.reply('You cant input a text with over 200 characters') const voiceChannel = message.member.voice.channel if(!voiceChannel) return message.reply(" Please enter a voice channel") const audioURL = await getAudioUrl(text, { lang: language, slow: false, host: 'https://translate.google.com', timeout: '150000' }) try { voiceChannel.join().then(connection => { const dispatcher = connection.play(audioURL) dispatcher.on('finish', () => { voiceChannel.leave() }) }) } } else { return message.reply(`That language is not supported, the current supported language : [${langlist.join(", ")}]`); } catch(err){ console.log(err) message.channel.send("There is an error")} } }

Estoy buscando en Internet, pero su problema si el intento no tiene captura, pero ya tengo uno.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Su instrucción catch está fuera del bloque if que tiene el bloque try . Esto es lo que hice para corregir el error:

  1. Mueva el bloque catch más cerca del try .
  2. Eliminar extra } que estaban causando errores.
  3. Corrige la sangría.

Aquí está el código:

 const {getAudioUrl} = require("google-tts-api") const langlist = ["en", "id"] let language = args[0] if(langlist.find(c => c === language)) { if(!language) return message.reply("Please enter the language") if(!args[1]) return message.reply("Please enter the text") const text = args.slice(1).join(" ") if(text.length > 200) return message.reply('You cant input a text with over 200 characters') const voiceChannel = message.member.voice.channel if(!voiceChannel) return message.reply(" Please enter a voice channel") const audioURL = await getAudioUrl(text, { lang: language, slow: false, host: 'https://translate.google.com', timeout: '150000' }) try { voiceChannel.join().then(connection => { const dispatcher = connection.play(audioURL) dispatcher.on('finish', () => { voiceChannel.leave() }) }) } catch(err){ console.log(err) message.channel.send("There is an error") } } else { return message.reply(`That language is not supported, the current supported language : [${langlist.join(", ")}]`); }

Un consejo para evitar este tipo de error: ¡sangría correctamente!

Si hubiera sangrado todo su código, habría sido mucho más fácil de leer y, por lo tanto, encontrar el error habría sido muy rápido (y ni siquiera tendría que preguntarle a Stack Overflow).

“Los programas deben estar escritos para que la gente los lea, y solo de manera incidental para que las máquinas los ejecuten”. -Harold Abelson

Si hace que su código sea más fácil de leer, depurar, reescribir, mantener, comprender, etc. será mucho más fácil, para usted y para todos los demás.

about 4 years ago · Santiago Gelvez 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!