Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在数组中添加消息?_Javascript_Node.js_Discord.js_K - Fatal编程技术网

Javascript 如何在数组中添加消息?

Javascript 如何在数组中添加消息?,javascript,node.js,discord.js,k,Javascript,Node.js,Discord.js,K,我想在发送bot消息后直接将其添加到数组中^^ 我试过这样的方法: task_chan.send('', { embed: { color: task_colors[0x808080], title: 'Tache n°1', thumbnail: { url: 'https://...' }, author: { name: 'Tache à prendre', icon_url:

我想在发送bot消息后直接将其添加到数组中^^

我试过这样的方法:

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=[]


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

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

.then(()=>tasks.push(bot.user.lastMessage))
将一个匿名函数传递给然后执行任务推送

。然后
还允许您访问异步
操作的结果。发送对您可能有用的
操作。您可以通过给匿名函数一个参数来访问它:

.then( (res) => { 
  console.log(res)
  tasks.push(bot.user.lastMessage) 
})

您需要传递
然后
一个函数。请尝试
。然后(()=>tasks.push(bot.user.lastMessage))
谢谢,它非常有效!:)