【问题标题】:Is there a way to display videos and GIFSs in Discord.js meme command有没有办法在 Discord.js meme 命令中显示视频和 GIFS
【发布时间】:2021-03-04 20:39:19
【问题描述】:

现在我的代码确实可以工作,但是当 reddit 帖子包含视频或 GIF 时,它就无法显示。有没有办法在 meme 命令中显示视频?如果您能提供真正有用的代码示例。

const got = require('got');
const Discord  = require('discord.js');

module.exports = {
    name: "meme",
    description: "Shows a random meme.",
    async execute(message, args) {
        const embed = new Discord.MessageEmbed();
        const subReddits = [
        'memes',
        'dankmemes',
        'Fauxcyrillic',
        'GachaLifeCringe',
        'terriblefacebookmemes',
        'CrappyDesign',
        'mildlyinteresting',
        'facepalm',
        'PerfectTiming',
        'photoshopbattles'
        ];
        const random = subReddits[Math.floor(Math.random() * subReddits.length)];

        try {
        const response = await got(`https://www.reddit.com/r/${random}/random/.json`);
        const body = JSON.parse(response.body);
        const posts = Array.isArray(body) ? body[0] : body;
        const post = posts.data.children[0].data;

        const memeUrl = `https://reddit.com${post.permalink}`;
        const memeImage = post.url;
        const memeTitle = post.title.slice(0, 256);

        embed.setTitle(`${memeTitle}`);
        embed.setURL(`${memeUrl}`);
        embed.setColor(26763);
        embed.setImage(memeImage);
        embed.setFooter(`From r/${random}`);

        message.channel.send(embed);
        } catch (err) {
        console.log(err);
        }
    },
};

【问题讨论】:

  • 检查post 是否有任何可能的视频链接属性。或者查看视频和 GIF 的链接,看看它们与普通图片​​链接有何不同

标签: discord.js


【解决方案1】:

我有同样的问题,并得到了有效的答案。您可以点击here进入问题。

【讨论】:

    猜你喜欢
    • 2022-01-12
    • 2020-10-11
    • 2021-08-07
    • 1970-01-01
    • 2015-03-12
    • 2020-08-04
    • 2010-11-06
    • 2021-10-10
    相关资源
    最近更新 更多