0

I want to use https://someapi.xyz/json/quote to display a quote when a user uses a command but I'm not really even sure where to start with implementing the html json and using it in a command. Messed around with snekfetch a bit but I don't think I had the setup correct so it didn't work. Here's what I tried:

const api = "https://someapi.xyz/json/quote";
const snekfetch = require('snekfetch');

module.exports = {
    name: "quote",
    description: "sends inspirational quote",
    async execute(message, args, Discord) {
snekfetch.get(api).then(console.log);
    }
}
FinallyComplete
  • 124
  • 1
  • 11

1 Answers1

1

Your response is JSON data, access the body then use it as any other JavaScript Object.

const api = "https://someapi.xyz/json/quote";
const snekfetch = require('snekfetch');

module.exports = {
    name: "quote",
    description: "sends inspirational quote",
    async execute(message, args, Discord) {
        snekfetch.get(api)
            .then(res => {
                const data = res.body;
                message.channel.send(`Quote from ${data.author}: ${data.quote}`);
            });
    }
}
Elitezen
  • 6,551
  • 6
  • 15
  • 29