我如何做到这一点,以便如果成员重复我的机器人发送的文本,我的机器人会发回一条消息?

时间:2019-04-27 17:44:12

标签: node.js discord.js

我想创建一个竞赛类型的事件,其中我的机器人生成一个随机数,如果成员回复相同的数字,则该机器人会发送一条新消息祝贺他们。

到目前为止,我所拥有的只是数字生成器,我不确定在发送相同数字时如何使我的机器人知道。

这是我到目前为止所拥有的一切:

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');```

1 个答案:

答案 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');
相关问题