0

我想在发送后直接将我的机器人消息添加到数组中^^

我试过这样的事情:

task_chan.send('', {
embed: {
      color: task_colors[0x808080],
      title: 'Tache n°1',
      thumbnail: {
         url: 'https://...'
      },
      author: {
         name: 'Tache à prendre',
         icon_url: 'https://zupimages.net/up/20/12/xqsf.jpg'
      },
      fields:[{
         name: "Tache à faire :",
         value: "...",
      },{
         name: 'Avancement de la tache :',
         value: 'Non commencée'
      }]
      }
})
.then(tasks.push(bot.user.lastMessage))

tasks使用定义var tasks = []

当我执行此代码时,它会正确发送消息,但不会将其保存在数组中,它是之前保存的消息。我希望你能帮帮我 :)

4

1 回答 1

0

只是为了澄清,.then需要一个函数作为它的第一个参数。所以正在发生的事情是tasks.push(bot.user.lastMessage)试图作为参数执行,并且可能一直在静默失败,或者您可能错过了错误消息。

.then( () => tasks.push(bot.user.lastMessage) )将匿名函数传递给 then 执行您的任务推送。

.then还可以让您访问.send可能对您有用的异步操作的结果。您可以通过给匿名函数一个参数来访问它:

.then( (res) => { 
  console.log(res)
  tasks.push(bot.user.lastMessage) 
})
于 2020-03-16T19:51:21.613 回答