繁体   English   中英

如何在 discord.js 中获得 twitch ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 预览?

[英]How can I get the twitch stream preview in discord.js?

目前我有这个代码来通知我的 discord 成员有人正在流式传输。 当我将图像设置为 twitch url 它只是由于某种原因无法加载它......我怎样才能获得正确的 twitch stream 预览?

client.on("presenceUpdate", (oldPresence, newPresence) => {
    if (!newPresence.activities) return false;
    newPresence.activities.forEach(activity => {
        if (activity.type == "STREAMING") {
            console.log(`${newPresence.user.tag} is streaming at ${activity.url}.`);
            const twitchAnnouncementChannel = newPresence.guild.channels.cache.find(ch => ch.id === `789277245617209354`)
            const twitchChannel = new Discord.MessageEmbed()
            .setColor("#400080")
            .setTitle(`${newPresence.user.tag} is now live on twitch`)
            .setURL(activity.url)
            .setDescription(`**Stream Started**`)
            .setImage(activity.url)
            .setTimestamp()
            .setFooter("Enigma")
            twitchAnnouncementChannel.send(`${newPresence.user.tag} IS NOW LIVE ON TWITCH GO CHECK HIM OUT! @everyone`, twitchChannel)
        };
    });
});

在你的情况下,这应该这样做。 To get the preview of a Twitch stream you need: https://static-cdn.jtvnw.net/previews-ttv/live_user_USERNAME-{width}x{height}.jpg , "activity.url" is only the channel url.

client.on("presenceUpdate", (oldPresence, newPresence) => {
    if (!newPresence.activities) return false;
    newPresence.activities.forEach(activity => {
        if (activity.type == "STREAMING") {
            console.log(`${newPresence.user.tag} is streaming at ${activity.url}.`);
            const twitchAnnouncementChannel = newPresence.guild.channels.cache.find(ch => ch.id === `789277245617209354`)
            const twitchChannel = new Discord.MessageEmbed()
                .setColor("#400080")
                .setTitle(`${newPresence.user.tag} is now live on twitch`)
                .setURL(activity.url)
                .setDescription(`**Stream Started**`)
                .setImage(`https://static-cdn.jtvnw.net/previews-ttv/live_user_${activity.url.split("twitch.tv/").pop()}-1920x1080.jpg`)
                .setTimestamp()
                .setFooter("Enigma");
            twitchAnnouncementChannel.send(`${newPresence.user.tag} IS NOW LIVE ON TWITCH GO CHECK HIM OUT! @everyone`, twitchChannel)
        };
    });
});

暂无
暂无

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

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