我想创建一个竞赛类型的事件,其中我的机器人生成一个随机数,如果成员回复相同的数字,则该机器人会发送一条新消息祝贺他们。
到目前为止,我所拥有的只是数字生成器,我不确定在发送相同数字时如何使我的机器人知道。
这是我到目前为止所拥有的一切:
client.on('message', function(message) {
console.log(message.content);
});
client.on("ready", function() {
console.log("Ready");
});
var code = Math.floor(Math.random() + Math.random() + Math.random() + Math.random() * 992875 + Math.random());
if (message.content === 'start competition') {
channel.send('Please repeat these numbers: ' + code);
};
client.login('token');```
答案 0 :(得分:1)
您需要将代码放入消息事件中,例如:
let code;
client.on('message', function(
if (message.content === 'start competition') {
code = Math.floor(Math.random() + Math.random() + Math.random() + Math.random() * 992875 + Math.random());
message.channel.send('Please repeat these numbers: ' + code);
} else if ( message.content == code) {
message.channel.send('Congratulations, ' + message.author + ' you won');
code = -1;
}
});
client.on("ready", function() {
console.log("Ready");
});
client.login('token');