Getting Rock, Paper, Scissors to work in discord.js with reactions

♀尐吖头ヾ 提交于 2021-02-11 15:46:39

问题


I am trying to create a Rock, Paper, Scissors for my discord bot in discord.js. I attempted to create on but it currently is not working.

I'd like the emojis to disappear once the reaction has been made and am unsure how to do that.

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!");
        }
    }
  },
};

回答1:


You can remove all reactions using message.reactions.removeAll() (note that this requires MANAGE_MESSAGES). I recommend placing this on the line after function getResult(choice, botChosen) {



来源:https://stackoverflow.com/questions/61310526/getting-rock-paper-scissors-to-work-in-discord-js-with-reactions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!