如何让一个成员重复我的机器人发送的文本,我的机器人会发回一条消息?

问题描述 投票:-1回答:1

我想制作一个竞赛类型的活动,我的机器人生成一个随机数,如果一个成员回复相同的号码,机器人会发送一条新的消息祝贺他们。

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

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

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');```
node.js discord.js
1个回答
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');
© www.soinside.com 2019 - 2024. All rights reserved.