我想制作一个竞赛类型的活动,我的机器人生成一个随机数,如果一个成员回复相同的号码,机器人会发送一条新的消息祝贺他们。
到目前为止我所拥有的只是数字生成器,我不知道如何在发送相同的号码时让我的机器人知道。
这是我到目前为止所做的一切:
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');```
您需要将代码放入消息事件中,如:
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');