I’m working on a Discord bot that should fetch random GIFs from Giphy but I keep running into issues. The code always jumps to the error handler and no GIFs are displayed. I’ve tried debugging by adding console logs but nothing shows up.
if (cmd === 'countdown') {
var targetDate = new Date("dec 25, 2024 00:00:00").getTime();
var now = new Date().getTime();
var timeLeft = targetDate - now;
var daysLeft = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
var hoursLeft = Math.floor((timeLeft %(1000 * 60 * 60 * 24))/(1000 * 60 * 60));
var minutesLeft = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
var secondsLeft = Math.floor((timeLeft % (1000 * 60)) / 1000);
giphyClient.search('gifs', {"q": "celebration"})
.then((result) => {
console.log(result);
var totalGifs = result.data.length;
var randomIndex = Math.floor((Math.random() * 10) + 1) % totalGifs;
var selectedGif = result.data[randomIndex];
msg.channel.send('🎄 **CHRISTMAS COUNTDOWN** 🎄');
msg.channel.send(`**${daysLeft}** days, **${hoursLeft}** hrs, **${minutesLeft}** mins, **${secondsLeft}** secs`, {
files: [selectedGif.images.fixed_height.url]})
})
.catch (() => {
console.log('Something went wrong with the API call...')
})
}
What could be causing the Giphy search to fail? Am I missing something in my API setup or is there an issue with how I’m handling the response data?