Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
How to send images using an api with discord.js

I am trying to create a simple discord bot which sends random pokemon names with their images with a specific command. I was successful in sending the image and name but only one is of them is sent. This is the code that I am using

 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) );

If I only try with -

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

It sends the image in the chat. Please help

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Doing

return data["name"] +data["sprites"]["front_default"]

returns the name and the URL together, or combines them.

I think you would want to return the name and the URL with a space next to each other, so you would need a space in between them.

You can fix this by either doing return `${data.name} ${data.sprites.front_default}` or return data.name + " " + data.sprites.front_default.

about 4 years ago · Juan Pablo Isaza Relatório

0

I solved this problem by ->

 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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda