我如何使这只适用于一个命令



我试图使用discord.js制作一个测验机器人,但当我运行此代码时,它会回复,即使它不是正确的词。我怎么修理它?

client.once('message', msg => {
if (msg.content === 'quiz') 
msg.channel.send('Ok quiz time!');
msg.channel.send('Can coding be hard. yes 👍 or no 👎')
msg.react('👍').then(() => msg.react('👎'));
const filter = (reaction, user) => {
return ['👍', '👎'].includes(reaction.emoji.name) && user.id === msg.author.id;
};
msg.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '👍') {
msg.reply('correct answer');
msg.channel.send ('Good job!')
} else {
msg.reply('Incorrect.');
}
})
.catch(_collected => {
msg.reply('You ran out of time.');
})
});

当我说一个不和谐的随机单词时,我的机器人会回复它"编码很难吗?是👍或否👎">

括号没有对齐修改后的代码应该是这样的。

client.once("message", (msg) => {
if (msg.content === "quiz") {
msg.channel.send("Ok quiz time!");
msg.channel.send("Can coding be hard. yes 👍 or no 👎");
msg.react("👍").then(() => msg.react("👎"));
const filter = (reaction, user) => {
return (
["👍", "👎"].includes(reaction.emoji.name) && user.id === msg.author.id
);
};
msg
.awaitReactions(filter, { max: 1, time: 60000, errors: ["time"] })
.then((collected) => {
const reaction = collected.first();
if (reaction.emoji.name === "👍") {
msg.reply("correct answer");
msg.channel.send("Good job!");
} else {
msg.reply("Incorrect.");
}
})
.catch((_collected) => {
msg.reply("You ran out of time.");
});
}
});

最新更新