简体   繁体   English

嵌入消息 gif 在 discord.js 中不起作用

[英]Embed message gif not working in discord.js

The bot sends a embed message (with the text and the gif).机器人发送嵌入消息(带有文本和 gif)。 However, the gif doesn't load at all.但是,gif根本不加载。 Everything seems to be working for the other commands but this particular command is not working.一切似乎都适用于其他命令,但这个特定的命令不起作用。 I really don't know, please help me.我真的不知道,请帮帮我。 My code:我的代码:

    const fetch = require('node-fetch');

module.exports = {
        name: 'hug',
        description: "hug command",
        async execute(message, args, Discord) {
            if (!message.mentions.users.first())
            return message.reply('***please mention someone.***');
        
        let keywords = 'anime hug';
        let url = `https://g.tenor.com/v1/search?q=${keywords}&key=${process.env.TENORKEY}&contentfilter=low`;
        let response = await fetch(url);
        let json = await response.json();
        const index = Math.floor(Math.random() * json.results.length);
        
              
                
        const embed = new Discord.MessageEmbed()
        .setColor('#FF8DC4')
        .setTitle(`*Aww how cute, ${message.author.username} gave ${message.mentions.users.first().username} a hug!*`,)
        
        .setImage(json.results[index].url)

    

        message.channel.send(embed + json.results[index].url)
        }
    }

Here's a picture of the message:这是消息的图片:

在此处输入图像描述

Error错误

Since you're using Tenor API to send random GIFs in the embed, the direct links do not support embeds.由于您使用 Tenor API 在嵌入中发送随机 GIF,因此直接链接不支持嵌入。 If you (console.log) the GIFs, it shows the direct Tenor link of the GIFs.如果您(console.log) GIF,它会显示 GIF 的直接 Tenor 链接。

Solution解决方案

You need to fetch the media link, changing .setImage(json.results[index].url to .setImage(json.results[index].media[0].url should fix the problem.您需要获取media链接,将.setImage(json.results[index].url.setImage(json.results[index].media[0].url应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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