我正在开发一些软件,以自动在您的默认浏览器中打开不和谐发布的链接。发送正常消息后,它可以工作,但我还需要它检查链接的嵌入并打开它。有什么想法吗?
linkclient2.on("message", message => {
if (message.channel.id == CHANNEL_ID) {
if (message.content.includes('https')) {
var link = message.content.split('https')[1]
console.log(link)
var linktest = `https${link}`
console.log(`opening ${linktest}`)
open(linktest)
}
// check if an embed contains 'https'
}
})
答案 0 :(得分:0)
此代码获取消息中的所有嵌入内容,并检查是否有任何描述是链接:
// check if an embed contains 'https'
else if (message.embeds) {
message.embeds.forEach(embed => {
if (embed.description.includes('https')) {
const link = embed.description.split('https')[1];
console.log(link);
const linktest = `https${link}`;
console.log(`opening ${linktest}`);
open(linktest);
}
});
}