让石头、布和剪刀与反应不协调地工作 [英] Getting Rock, Paper, Scissors to work in discord.js with reactions

查看:6
本文介绍了让石头、布和剪刀与反应不协调地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在discord.js中为我的不一致机器人创建一个石头、布、剪刀。我尝试在上创建,但目前不起作用。

我希望表情符号在做出反应后消失,但不确定如何做到这一点。

module.exports = {
  name: "rps",
  description: "A game of Rock, Paper, Scissors!",
  execute(message) {
    var rps = ["🗿", "📜", "✂️"]
    const m = message.channel.send("Let's play a game of Rock, Paper, Scissors! Please react what you would like to choose with the emojis below!").then((message) => {
      message.react("🗿");
      message.react("📜");
      message.react("✂️");
    });
    const reacted = promptMessage(m, message.author, 30, rps);

    const botChoice = rps[Math.floor(Math.random()*rps.length)];
    const result = getResult(reacted, botChoice);
    m.clearReactions();

    message.channel.send(`You chose ${reacted} and I chose ${botChoice}`);

    function getResult(choice, botChosen) {
      if(choice === "🗿" && botChoice === "✂️") {
          return message.channel.send("You win! I had fun, let's play again!");
        } else if (choice === "📜" && botChoice === "🗿") {
          return message.channel.send("You win! I had fun, let's play again!");
        } else if (choice === "✂️" && botChoice === "📜"){
          return message.channel.send("You win! I had fun, let's play again!");
        } else if (choice === botChosen) {
          return message.channel.send("It's a tie!");
        } else {
          return message.channel.send("You lost! I had fun, let's play again!");
        }
    }
  },
};

推荐答案

您可以使用message.reactions.removeAll()删除所有反应(请注意,这需要Manage_Messages)。我建议将此放在function getResult(choice, botChosen) {

之后

这篇关于让石头、布和剪刀与反应不协调地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆