【发布时间】:2020-12-21 00:22:04
【问题描述】:
目前我有这个代码来通知我的不和谐成员有人正在流式传输。当我将图像设置为 twitch url 时,由于某种原因它不会加载它......我怎样才能获得正确的 twitch 流预览?
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)
};
});
});
【问题讨论】:
-
好吧,twitch url 只是一个流的链接,它不是一个图像链接。您需要使用 twitch API 本身来获取预览图像。您可以尝试使用this answer 这样做(它是从 2018 年开始的,因此可能与现在有些不同,但总体上应该是相同的基本过程)。
标签: javascript discord.js