Javascript 如何在数组中添加消息?
我想在发送bot消息后直接将其添加到数组中^^ 我试过这样的方法: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:
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))
谢谢,它非常有效!:)