我正在为我的不和谐机器人制作一个命令,我需要一些帮助,它应该是一个翻转硬币的命令,你可以在头部或尾部之间进行选择,它会告诉你是否输赢,这里是到目前为止我所拥有的:
var coins = [ //for the coin command
"heads",
"tails"
];
"coin": {
proc: function(bot,msg,args) {
coinz = coins[Math.floor(Math.random() * coins.length)];
if (args === "heads" || args === "tails" || !`${args}` === `${coinz}`) {
msg.channel.send(`Your bet: \`${args}\`, outcome: \`${coinz}\` you lose`)}
else if (args === "heads" || args === "tails" || `${args}` === `${coinz}`) {
msg.channel.send(`Your bet: \`${args}\`, outcome: \`${coinz}\` you win`);
} else return msg.channel.send('Must be either `sr!heads` or `sr!tails`').then(msg=>msg.delete(5000));
}
},
// this is obviously not the full code, just what is needed to be seen!
这是错误的图像:
答案 0 :(得分:1)
您的条件设置不正确。如果args是头或尾,它会触发你输。尝试这样设置。
if (args === "heads" || args === "tails"){
if(args != coinz) {
// Display you lose message
}
else {
// Display you win message
}
}
else {
// Display incorrect input
}