Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord tenor gif embed doesn't load

I’m having a problem with my code. My code sends the gif in the embed but the gif doesn’t load so I want to know if it is from my code or from discord/tenor.

This is my code:

client.on('message', message => {
  if (message.content.startsWith(prefix + 'punch')) {
    const user = message.mentions.users.first();
    if (user) {
      request('https://api.tenor.com/v1/random?key==punch&limit=1', function (error, response, body) {
        if (!error && response.statusCode == 200) {
          const data = JSON.parse(body);
          const gif = data.results[0].url;
          const embed = new MessageEmbed()
            .setTitle(`${message.author.username} a fraper ${user.username}`)
            .setColor(0x00AE86)
            .setImage(gif)
            .setTimestamp()
            .setFooter('GIFER', 'https://discord.com/api/oauth2/authorize?client_id=962008158727974922&permissions=8&scope=bot');
          message.channel.send({ embeds: });
        }
      });
    } else {
      message.channel.send('Vous devez mentionner un utilisateur !');
    }
  }
});

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

data.results[0].url is not a direct link to the file, but the short URL to view the post on tenor.com. If you check https://tenor.com/becER.gif, it redirects to https://tenor.com/view/good-ebening-good-evening-coach-looking-searching-gif-15739239.

You should use the media key instead. It’s an array of dictionaries with the format (like gif, mp4, webm, etc.) as the key and a media object (with keys like size, duration, and url) as the value. It means you can get the URL of the gif like this:

const gif = data.results[0].media[0].gif.url;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading