如何向功能添加功能

我目前有一个cron作业功能,每天早上7:00 AM发送一条消息,它工作正常,但现在我希望它从Trello卡中获得消息,而Trello部分则工作正常,但是当我把他们在一起是行不通的。有任何想法吗?这是我到目前为止所拥有的:

var job = new CronJob('01 15 18 * * *',function() {
        let listID = "5ec3fda8a26c384e44f063bb";
trello.getcardsOnListWithExtraParams(listID,"pos:top",function (error,trelloCard) {
        console.log('Found card:',trelloCard[0].name);
})
const wyrEmbed = new discord.RichEmbed()
      .setTitle("❓**WOULD YOU RATHER**❓")
      .addField(
        "**THE WOULD YOU RATHER**","test: " + trelloCard[0].name)
      .setDescription(
        "? Top o' the mornin’ to ya! All throughout the night,I’ve been preparing a would you rather question for all of you! I can’t wait to see all of the answers you guys think of! "
      )
      .setTimestamp()
      .setfooter("Munchies Ice Cream",client.user.avatarURL)
      .setThumbnail("https://t4.rbxcdn.com/366f4da2e1924b6e4b0816086b485f05")
      .setColor("7ab7e2"); 
        const wyrthing = client.channels.get("688177088573997066")
  wyrthing.send(wyrEmbed)
    console.log('You will see this message every second')
},null,true,'America/New_York'
);
})
zhaozhixuan 回答:如何向功能添加功能

您的代码基本上尝试这样做(按此顺序):

  • 开始获取Trello卡
  • 使用(不存在的)Trello卡发送嵌入
  • 之后,当检索到Trello卡时:记录“找到的卡:”

这是因为trelloCard是一个异步函数。您正在将结果let listID = "5ec3fda8a26c384e44f063bb"; trello.getCardsOnListWithExtraParams(listID,"pos:top",function (error,trelloCard) { console.log('Found card:',trelloCard[0].name); const wyrEmbed = new discord.RichEmbed() .setTitle("❓**WOULD YOU RATHER**❓") .addField("**THE WOULD YOU RATHER**","test: " + trelloCard[0].name) .setDescription( "? Top o' the mornin’ to ya! All throughout the night,I’ve been preparing a would you rather question for all of you! I can’t wait to see all of the answers you guys think of! " ) .setTimestamp() .setFooter("Munchies Ice Cream",client.user.avatarURL) .setThumbnail("https://t4.rbxcdn.com/366f4da2e1924b6e4b0816086b485f05") .setColor("7ab7e2"); const wyrthing = client.channels.get("688177088573997066") wyrthing.send(wyrEmbed) }) 作为回调函数的参数,但是在向嵌入中添加字段时,您试图在回调之外访问它。

将其放在您的cron函数中:

map()
本文链接:https://www.f2er.com/2315527.html

大家都在问