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

269
Views
No se puede enviar un error de mensaje vacío al intentar enviar la respuesta de Axios en Discord.js

Cuando envío un mensaje a mi bot, arroja el siguiente error:

 (node:5852) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message at c:\Users\Owner\Desktop\selfbot\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15 at c:\Users\Owner\Desktop\selfbot\node_modules\snekfetch\src\index.js:215:21 at processTicksAndRejections (internal/process/task_queues.js:97:5) (Use `node --trace-warnings ...` to show where the warning was created) <node_internals>/internal/process/warning.js:33 (node:5852) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) <node_internals>/internal/process/warning.js:33

Este es mi código:

 bot.on("message", async function(message) { try { if (message.author == bot.user) return; if (message.channel.type == "dm" || message.channel.type == "group") { await new Promise(resolve => setTimeout(resolve, 3000)); if (!message.channel.typing) { message.channel.startTyping(); setTimeout(function() { const URI = `http://api.brainshop.ai/get?bid=161231&key=80GaZTVrQICIxCnI&uid=[uid]&msg=${message}`; const encodedURI = encodeURI(URI); axios.get(encodedURI) .then(async response => { var data = response message.reply(response) }); message.channel.stopTyping(); }, 5000); } } } catch (e) { console.log(e) } });

Estoy creando un bot de discordia que envía un mensaje generado por IA a los usuarios. Cuando envío la respuesta, dice que es un mensaje vacío. ¿No estoy analizando algo bien?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El problema es que la response es un objeto y debe enviar una cadena o un objeto con claves específicas. Como su objeto de response no tiene estas claves, el contenido está vacío.

El método get de Axios devuelve un objeto que tiene una propiedad data ; es la respuesta proporcionada por el servidor. La respuesta de la API de BrainShop es un objeto JSON, con una clave cnt . Probablemente significa contenido.

Para obtener el contenido de texto de la API, deberá usar response.data.cnt :

 if (!message.channel.typing) { message.channel.startTyping(); setTimeout(async () => { const URI = `http://api.brainshop.ai/get?bid=161231&key=80GaZTVrQICIxCnI&uid=[uid]&msg=${message}`; const encodedURI = encodeURI(URI); const response = await axios.get(encodedURI); message.reply(response.data.cnt); message.channel.stopTyping(); }, 5000); }
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!