等待具有异步过滤器的等待message.awaitReaction

问题描述 投票:0回答:1

为什么我的控制台在“已启动”之前记录“已完成”?为什么我不能等待message.awaitReactions(); ?

const filter = async /*It is here for no reason but without it does not work neither*/ (reaction, user) => {
  if (user.id == players[p].user.id && aEmojis.indexOf(reaction.emoji.name) != -1) {
     console.log("Started");
     attackedIndex = aEmojis[aEmojis.indexOf(reaction.emoji.name)+1];
     message.delete();
     return true;
  }
  return false;
};


await message.awaitReactions(filter, {max: 1});
console.log("Finished");
javascript asynchronous async-await discord.js
1个回答
0
投票

await在异步函数中工作

  (async function() {
  const filter = async (reaction, user) => {
  if (user.id == players[p].user.id && aEmojis.indexOf(reaction.emoji.name) != -1) {
     console.log("Started");
     attackedIndex = aEmojis[aEmojis.indexOf(reaction.emoji.name)+1];
     message.delete();
     return true;
  }
  return false;
  };


  await message.awaitReactions(filter, {max: 1});
  console.log("Finished");
  })();

推荐问答