返回 If 语句

时间:2021-04-19 08:07:47

标签: javascript node.js arrays map-function

我有一个对象数组,其中包含 queryqLengthqStatusanswer

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");
  } 
 }

非常感谢任何帮助!

0 个答案:

没有答案
相关问题