【问题标题】:Bot to reply to a part of a message机器人回复消息的一部分
【发布时间】:2020-12-20 23:48:53
【问题描述】:
client.on('message', msg => {
  if (msg.content === 'good morning!')
msg.reply('morning!');
 }
 );

当我说“早上好!”时,此命令有效,但如果我希望它回复“我刚醒来,早上好!”之类的内容,代码应该是什么?而且我的意思并不是确切地说,我只是说如果触发消息在另一条消息的中间

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    您可以使用String.prototype.includes() 函数,无论字符串是否包含给定参数,它都会返回boolean

    const message = 'Happy Birthday Random Person!';
    const otherMessage = 'Happy Birthday Person I Know!';
    
    if (message.toLowerCase().includes('random person'))
      console.log("You shouldn't be talking to random people on the internet >:(");
      
    if (otherMessage.toLowerCase().includes('random person'))
      console.log("You shouldn't be talking to random people on the internet >:(");
    else console.log('Good, you were being safe ༼ つ ◕_◕ ༽つ')
    if (message.content.toLowerCase().includes('good morning')) {
      // do stuff
    };
    

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 2022-10-19
      • 2021-07-01
      相关资源
      最近更新 更多