简体   繁体   English

DISCORD.JS:Message.awaitReactions 未触发

[英]DISCORD.JS: Message.awaitReactions not firing

When I run this code sendReact() executes but nothing else—no errors.当我运行此代码时,sendReact() 会执行但不会执行任何其他操作——没有错误。 The.catch() function is the only thing that executes after 5 seconds. the.catch() function 是唯一在 5 秒后执行的东西。 When I react to my embed that I created with sendReact(), nothing happens.当我对使用 sendReact() 创建的嵌入做出反应时,没有任何反应。 This happens in my command file as well as my index.js file if I moved the code there.如果我将代码移到那里,这会发生在我的命令文件和我的 index.js 文件中。 Nothing is being logged to the console.没有任何内容被记录到控制台。

  var pick = Math.floor(Math.random() * 3) + 1; // 1-rock 2-paper 3-scissors
  let playerPick = 0;

  sendReact() // sends the embed message with the reactions

  message.awaitReactions((reaction, user) => user.id == message.author.id && (reaction.emoji.name == '🌑' || reaction.emoji.name == '📄' || reaction.emoji.name == '✂️'),
  { max: 1, time: 5000 }).then(collected => {

    if (collected.first().emoji.name == '🌑') {
      console.log('rock');
      playerPick = 1;
    } else if (collected.first().emoji.name == '📄') {
      console.log('paper');
      playerPick = 2;
    } else if (collected.first().emoji.name == '✂️') {
      console.log('scissors');
      playerPick = 3;
    }

    console.log("Player pick: " + playerPick);
    console.log("CPU pick: " + pick);

  }).catch(() => {
    message.reply('No reaction after (how many) seconds, game cancelled.');
  });

You're creating an embed with sendReact() , but then you call message.awaitReactions(...) .您正在使用sendReact()创建嵌入,但随后调用message.awaitReactions(...) Which message is that referring to?那是指哪个消息? Most likely you're waiting for reactions on the message that triggered this command, instead of on the message with the embed you sent with sendReact() .您很可能正在等待对触发此命令的消息的反应,而不是对您使用sendReact()发送的嵌入消息的反应。 The only way you can tell the bot to wait for reactions on the new message is to get a reference to it, and call awaitReactions() on that reference.您可以告诉机器人等待对新消息的反应的唯一方法是获取对它的引用,并在该引用上调用awaitReactions()

So, for example:所以,例如:

//in an async function...
let gameMessage = await sendReact();

gameMessage.awaitReactions(...).then(collected => {
  //handle reaction
});

The reason to this is because you're awaiting reactions on your own message .这是因为您正在等待对您自己的message的反应。

You need to make awaitReactions() listen to reactions on the embed you're sending.您需要让awaitReactions()收听对您发送的嵌入的反应。

const msg = await sendReact()
msg.awaitReactions((reaction, user) => user.id == message.author.id && (reaction.emoji.name == '🌑' || reaction.emoji.name == '📄' || reaction.emoji.name == '✂️'),
  { max: 1, time: 5000 }).then(collected => { })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM