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

196
Views
Cómo enviar imágenes usando una api con discord.js

Estoy tratando de crear un bot de discordia simple que envíe nombres de Pokémon aleatorios con sus imágenes con un comando específico. Tuve éxito en el envío de la imagen y el nombre, pero sólo se envía uno de ellos. Este es el codigo que estoy usando

 var random= Math.floor( Math.random() * 800 ) <br> function getPoke() {<br> return fetch("https://pokeapi.co/api/v2/pokemon/" + random) .then( res => { <br> return res.json() <br> } ) <br> .then(data => {<br> return data ["name"] +data["sprites"]["front_default"]<br> } ) <br> } if (msg.content === "$poke") { <br> getPoke().then (pokemon=> msg.channel.send ( pokemon) );

Si solo intento con -

 return data["sprites"]["front_default"]

Envía la imagen en el chat. Por favor ayuda

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

0

Haciendo

devolver datos["nombre"] +datos["sprites"]["front_default"]

devuelve el nombre y la URL juntos, o los combina.

Creo que le gustaría devolver el nombre y la URL con un espacio al lado del otro, por lo que necesitaría un espacio entre ellos.

Puede solucionar esto ya sea return `${data.name} ${data.sprites.front_default}` o return data.name + " " + data.sprites.front_default .

about 4 years ago · Juan Pablo Isaza Report

0

Resolví este problema por ->

 var random= Math.floor( Math.random() * 800 ) function getPoke() { return fetch("https://pokeapi.co/api/v2/pokemon/" + random) .then( res => { return res.json() } ) .then(data => { return data ["name"] } ) } if (msg.content === "$poke") { getPoke().then(poek => msg.channel.send(poek,{ files:[ 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/'+random+'.png' ] } ).then( random=Math.floor(Math.random() *898) )); }
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!