Code Introduction
I was making a command where if you type p!shrug
it sends a random shrug GIF from Tenor. I'm using Tenor API and node-fetch
for my code.
Problem
The bot sends an embed as requested but the image in the embed is a Discord Poop image
My Code
const Discord = require('discord.js');
const fetch = require('node-fetch');
module.exports = {
name: 'shrug',
description: 'Shruggy Shruggy',
async execute(client, message, args){
const url = `https://api.tenor.com/v1/search?q=anime_shrug&key=${process.env.tenorkey}&limit=24`
const res = await fetch(url);
const result = await res.json();
const gif = Math.floor(Math.random() * result.results.length);
const newGIF = new Discord.MessageEmbed()
.setAuthor(`${message.author.username} shrugs~`, message.author.displayAvatarURL())
.setImage(result.results[gif].url)
.setColor('RANDOM')
message.channel.send(newGIF)
.then(console.log(result.results[gif].url))
}
}
More Info
The GIF works when I copy the link of GIF from the embed and paste it, it loads.
Answer
Ok so basically I fixed it with just a small change
result.results[gif].url
returns the Tenor GIF link which cannot be used as an image in an embed.And the change I made was :-
result.results[gif].url
to result.results[gif].media[0].url
which returns a media link that can be used in an embed.I would be thankful for further help, but this did fix my problem.