简体   繁体   中英

Now showing URL image discord.js

This is the code:

fetch(`https://api.tenor.com/v1/random?key=${tenorAPI}&q=anime+kiss&limit=1.`)
  .then(res => res.json())
  .then(json => message.channel.send() + message.say(json.results[0].url))
    
  const embed = new MessageEmbed()
      .setDescription(`**${user.username}** you've kissed by **${message.author.username}**! OwO`)
      .setColor("RANDOM")
      .setImage(`https://api.tenor.com/v1/random?key=${tenorAPI}&q=anime+kiss&limit=1.gif`)
   message.channel.send(embed).then(message.react('🥰'));
    return;

I want to know how can I do to see the GIF

看

Other command not embedded it shows

在此处输入图片说明

It works perfectly now, this is the code,it is similar to the previous user but there was an error

const embed = new MessageEmbed()
      .setDescription(`**${user.username}** you've kissed by **${message.author.username}**! OwO`)
      .setColor("RANDOM")
fetch(`https://api.tenor.com/v1/random?key=${tenorAPI}&q=anime+kiss&limit=1`)
  .then(res => res.json())
  .then(json => {
     embed.setImage(json.results[0].media[0].gif.url);
     message.channel.send(embed).then(message.react('🥰'));
   })

I've also found this problem when I created a gif search function on my bot.

The way around this is to not use the url property, but rather the .media[0].gif.url when using the setImage method on embeds.

Also, it's a good idea to not set your image to have your api key, lol

The following code should work:

const embed = new MessageEmbed()
      .setDescription(`**${user.username}** you've kissed by **${message.author.username}**! OwO`)
      .setColor("RANDOM")
fetch(`https://api.tenor.com/v1/random?key=${tenorAPI}&q=anime+kiss&limit=1.`)
  .then(res => res.json())
  .then(json => {
     embed.setImage(json.results[0].media[0].gif.url);
     message.channel.send(embed).then(message.react('🥰'));
   })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM