Skip to content
Advertisement

sending info from api to discord in a message (discord.js)

Hey i have a question about how to send data over to a message in discord.js. The code that im using now is kinda working. Its just giving me the response [Object Object]

client.on("message", msg => {
  var axios = require("axios").default;

var options = {
  method: 'GET',
  url: 'https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random',
  headers: {
    accept: 'application/json',
    'X-RapidAPI-Host': 'matchilling-chuck-norris-jokes-v1.p.rapidapi.com',
    'X-RapidAPI-Key': '0f787e5af5msh468814e0b585173p1cacafjsn7d774dfb44ff'
  }
}
  if(msg.content === "chuck"){
    axios.request(options).then(function (response) {
      let datachuck = response.data
        msg.channel.send(`${datachuck}`)
          console.log(response.data)
     
}).catch(function (error) {
    console.error(error);
});
  }
})

Advertisement

Answer

the respone.data is not a object. That’s why i’m getting [object, object] So the solution is let datachuck = response.data.value

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement