我有一个机器人通过私人消息向用户提问。我只希望机器人只接受某些单词作为答案。
例如,询问用户他们的性别。我希望选项为“男”,“女”和“其他”。如果漫游器收到的不是这些答案,我还想说“请输入“男性”,“女性”或“其他”。我尝试了几种似乎无效的方法。 ,在我搞砸的范围之外,但是会接受“ cat”(例如,作为性别),因此我显然希望它仅接受一些答案。不知道指定if的if语句是否可行。我知道它本身是如何工作的,但是与await结合使用时,我很困惑...
这是我上次尝试的代码,无济于事(更不用说它给出了语法错误/由于我弄乱的行而导致了意外的令牌)
module.exports.run = async (bot, message, args) => {
message.author.send(`THIRD QUESTION, **What is the gender of your Brawler or Character?** Please enter "Male", "Female" or "Other".`)
.then((newmsg) => { //Now newmsg is the message you send to the bot
newmsg.channel.awaitMessages(response => response.content.includes("Male", "Female", "Other") {
max: 1,
time: 300000,
errors: ['time'],
}).then((collected) => {
newmsg.channel.send(`Your brawler's gender is: **${collected.first().content}**
If you are okay with this gender, type !profilerace to continue the profile creation process!
If you would like to edit your gender, please type !profilegender`)
con.query(`UPDATE profile SET gender = '${collected.first().content}' WHERE id = ${message.author.id}`);
console.log("1 record updated!")
}).catch(() => {
newmsg.channel.send('Please submit an age for your character. To restart Profile creation, please type "!profilecreate" command in Profile Creation channel on the server.');
});
//con.query(sql, console.log);
//if (err) throw err;
//console.log("1 record inserted!")
});
}
编辑:在下面的评论中获得了一些帮助之后,我得到了类似的结果。我一直收到语法错误。我觉得我不知道我在这里做什么。 lmao
module.exports.run = async (bot, message, args) => {
message.author.send(`THIRD QUESTION, **What is the gender of your Brawler or Character?** Please enter "Male", "Female" or "Other".`)
.then((newmsg) => { //Now newmsg is the message you send to the bot
newmsg.channel.awaitMessages(response => response.content, {
max: 1,
time: 300000,
errors: ['time'],
})
.then((collected) => {
if (response.content === "Male" || response.content === "Female"|| response.content === "Other") {
return
newmsg.channel.send(`Your brawler's gender is: **${collected.first().content}**
If you are okay with this gender, type !profilerace to continue the profile creation process!
If you would like to edit your gender, please type !profilegender`)
con.query(`UPDATE profile SET gender = '${collected.first().content}' WHERE id = ${message.author.id}`);
console.log("1 record updated!")}
} else {
newmsg.channel.send("Please submit 'Male', 'Female' or 'Other'. Type !profilegender to restart the choice of gender.")
}
}).catch(() => {
newmsg.channel.send('Please submit an age for your character. To restart Profile creation, please type "!profilecreate" command in Profile Creation channel on the server.');
});
});
}
感谢您的帮助!
答案 0 :(得分:1)
我不确定您的意思到底是什么,但是我将创建一个ArrayList并检查消息的内容是否与ArrayList中的值之一匹配,如下所示:
null