如何发送随机消息?

时间:2021-05-13 05:25:37

标签: discord discord.js

(现在...是的,我知道标题可能是废话。)

假设我有 6 个嵌入。你知道,就像……游戏死了。 我想在运行命令 $roll 后发送这些嵌入之一。 我是这样编码的:

message.reply(`${ one || two || three || four || five || six }`);

然而,每次我运行命令时,它只说One... Here's an image.

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:2)

当您使用 one || two || three || four || five || six 时,它始终为一,因为一始终为真。 所以如果你想发送一个随机值,试试这个代码

const choices = [one, two, three, four, five, six]
message.reply(choices[Math.floor(Math.random() * choices.length)])

答案 1 :(得分:0)

    function randomnumb() {
    var rand = [
      "one",
      "two",
      "three",
      "four",
      "five",
      "six"
    ];

    return rand[Math.floor(Math.random() * rand.length)];
  }
  
  message.channel.send(randomnumb());