所以我正在编码这个不和谐机器人,我希望机器人能够进行滚动游戏 当有人输入“jroll”时,机器人运行这个:
var roll = (Math.floor(Math.random()*200)+1);
if (roll <=100){message.reply('Thats not enough, keep rolling')}
else{message.reply('Uuuuuh now those are some monies goy, you may get help')}
我想弄清楚的是如何让这个滚动游戏“jroll”运行 你可以告诉我,我不是在js经历过。
答案 0 :(得分:0)
一个非常简单的例子让你开始,继续滚动lol
(我们的想法是你需要一个点击事件,所以每次你点击,你都会得到一个新的卷并根据卷号输出消息)
document.getElementById('rollnow').addEventListener("click", function() {
var roll = (Math.floor(Math.random() * 200) + 1);
console.log('This roll is: ' + roll);
if (roll <= 100) {
//message.reply('Thats not enough, keep rolling')
console.log('Thats not enough, keep rolling');
} else {
//message.reply('Uuuuuh now those are some monies goy, you may get help')
console.log('Uuuuuh now those are some monies goy, you may get help');
}
});
&#13;
<button id="rollnow">ROLL NOW</button>
&#13;
答案 1 :(得分:0)
我在解释您的问题,因为您不了解如何从特定邮件中触发您的代码,如果是这样,您可以执行以下操作:
client.on("message", function(message) {
if (message.content == "jroll") {
var roll = (Math.floor(Math.random()*200)+1);
if (roll <= 100) {
message.reply('Not enough, keep rolling');
}
else {
message.reply('You win');
}
}
});