反应在一个不一致的秩序js

问题描述:

我想添加一个消息与反应,但我想反应有一定的顺序。问题是当我执行命令添加该消息时,反应会随机添加。反应在一个不一致的秩序js

代码:

 case "helptest": 
 
\t indexTest = 0; 
 
\t comandUser = message.author.username; 
 
\t message.channel.send(mesajeTest[indexTest]).then(function (message) { 
 
\t \t message.react("⏪") 
 
\t \t message.react("▶") 
 
\t \t message.react("◀") 
 
\t \t message.react("⏩") 
 
\t }); 
 
\t break;

我想要的顺序是在代码是在反应消息,任何溶液?

解决了异步函数问题

\t \t case "helptest": 
 
\t indexTest = 0; 
 
\t comandUser = message.author.username; 
 
\t message.channel.send(mesajeTest[indexTest]).then(async function (message) { 
 
\t \t await message.react("⏪") 
 
\t \t await message.react("◀") 
 
\t \t await message.react("▶") 
 
\t \t await message.react("⏩") 
 
\t }); 
 
\t break;

你的发送函数到底是什么?什么的承诺?也许多个Promise在第一个回调完成之前得到解决。

您是否尝试过使用Promise.each()

With Promise.each()迭代顺序发生。如果迭代器函数返回一个promise或一个thenable,那么在继续下一次迭代之前,会等待promise的结果。