【问题标题】:How to check if a discord embed contains a link?如何检查不和谐嵌入是否包含链接?
【发布时间】:2020-11-26 02:27:36
【问题描述】:

我正在开发一些软件来自动打开默认浏览器中不和谐发布的链接。它在发送正常消息时起作用,但我还需要它来检查嵌入的链接并打开它。有什么想法吗?

    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'
            
              
        }
    })

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    此代码获取消息中的所有嵌入内容并检查是否有任何描述是链接:

    // 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);
        }
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2022-12-18
      • 2021-08-04
      • 2021-07-23
      • 1970-01-01
      • 2017-08-04
      • 2021-07-01
      • 2022-01-19
      • 2021-08-11
      • 1970-01-01
      相关资源
      最近更新 更多