Home > Mobile >  Discord tenor gif embed doesn't load
Discord tenor gif embed doesn't load

Time:04-13

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: [embed]});
        }
      });
    } else {
      message.channel.send('Vous devez mentionner un utilisateur !');
    }
  }
});

CodePudding user response:

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;
  • Related