【问题标题】:How do I make a randomizer within an autoresponse?如何在自动回复中制作随机数?
【发布时间】:2021-01-22 16:28:04
【问题描述】:

我想这样当你说某件事时,你会从许多可能的回应中得到一个。 我现在的代码是:

      client.on('message', msg => {
    if (msg.content === '<response trigger>') {
    msg.channel.send('<response>');
    }
  });

【问题讨论】:

    标签: node.js discord.js bots


    【解决方案1】:

    在if语句下,放入

    var responseList = [
    "Response one",
    "Response two",
    "Response three",
    "And so on"
    
    const response = Math.floor(Math.random() * responseList.length)
    
    message.channel.send(responseList[response]
    
    

    您可以根据需要添加任意数量的回复,它仍然有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-28
      • 2014-09-04
      • 1970-01-01
      • 2020-04-19
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多