我有一个对象数组,其中包含 query
、qLength
、qStatus
、answer
。
const commands = [
{
query: 'hello',
qLength: 5,
qStatus: 'reply',
answer: 'Hello ! Have a nice day!'
}
]
我正在运行一个 map
函数来根据数组返回 if 语句。但是,它说:Unreachable code detected !
。这是函数:
commands.map((command) => {
return (
if(msg.content.substr(0, command.qLength).toLocaleLowerCase() === command.query) {
if(command.qStatus === 'reply') {
msg.reply(command.answer);
}
}
)
});
因此,我想要的是 if 语句。类似的东西:
if(msg.content.substr(0, 5).toLocaleLowerCase() === "hello") {
if("reply" === 'reply') {
msg.reply("Hello ! Have a nice day!");
}
}
if(msg.content.substr(0, 5).toLocaleLowerCase() === "hi") {
if("reply" === 'reply') {
msg.reply("Hi");
}
}
非常感谢任何帮助!