javascriptnode.jsdiscord.jsgiphygiphy-api

Cannot get gifs with giphy using discord.js, making a bot


if (command === 'fetar') {
    var deadline = new Date("apr 19, 2020 00:00:00").getTime();
    var currentDate = new Date().getTime();
    var remainingTime = deadline - currentDate;

    var days = Math.floor(remainingTime / (1000 * 60 * 60 * 24)); 
    var hours = Math.floor((remainingTime %(1000 * 60 * 60 * 24))/(1000 * 60 * 60)); 
    var minutes = Math.floor((remainingTime % (1000 * 60 * 60)) / (1000 * 60)); 
    var seconds = Math.floor((remainingTime % (1000 * 60)) / 1000);

    giphy.search('gifs', {"q": "food"})
        .then((response) => {
            console.log(response);
            var totalResponses = response.data.length;
            var responseIndex = Math.floor((Math.random() * 10) + 1) % totalResponses;
            var responseFinal = response.data[responseIndex];
            message.channel.send('🍖 **E N D   O F   L E N T** 🍖');
            message.channel.send(`**${days}** days, **${hours}** hrs, **${minutes}** mins, **${seconds}** secs`, {
                files: [responseFinal.images.fixed_height.url]})
        })
        .catch (() => {
            console.log('Ya messed up again...')
        })

}

Tried to use this code but to no avail, it goes directly to my error catch and does not generate a gif. I tried to console log the steps leading up to this but nothing displayed.


Solution

  • You probably are not using an API key, according to giphy's docs 403 status means

    You weren't authorized to make your request; most likely this indicates an issue with your API Key.

    If you are not using an API key you can get it by following this guide