Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

262
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda