Saturday, 29 April 2017

Unirest request in Node.js

I am quite new to javascript and Node.js, and I came because I want to make a Discord bot for people playing card games. I am using the discord.js-commando libraries.

I kinda need a 'complete guide' at this. I'd like to know more about requesting information from a Mashape API with Unirest (specifically this one (hearthstone)), how the parameters work, how do I parse a JSON file for a response and a couple examples with this API (my main goal is to get the image URL of a card).

Here is the code of the command I am coding:

const commando = require('discord.js-commando');

class HSCommand extends commando.Command {
    constructor(client) {
        super(client, {
            name: 'hs',
            group: 'cards',
            memberName: 'cards',
            description: "Fetches the image of an Hearhtstone card and posts its details in the chat"
        });
    }

    async run(message, args) {
        if (message.author.bot) return;

        var requestcardname = args;
        var url = 'https://omgvamp-hearthstone-v1.p.mashape.com/cards/search/' + requestcardname;
        var requesturl = url.replace(" ", "%20");
        console.log(requesturl);


via jsgarden

No comments:

Post a Comment