我正在为我和我的朋友们制作一个Discord Bot。我做了一个8Ball脚本,它只给我一个答案。这是我的变量:

var rand = ['Yes', 'No', 'Why are you even trying?', 'What do you think? NO', 'Maybe', 'Never', 'Yep'];

var yesOrNo = rand[Math.floor(Math.random()*rand.length)];


这是运行变量的命令:

if(input == "!8BALL")
{
    bot.reply(message, 'Your anwser is: ' + yesOrNo);
}

最佳答案

您应该创建一个函数并在用户放入!8BALL时调用它。

function doMagic8BallVoodoo() {
    var rand = ['Yes', 'No', 'Why are you even trying?', 'What do you think? NO', 'Maybe', 'Never', 'Yep'];

    return rand[Math.floor(Math.random()*rand.length)];
}

// Later in the code:
if(input == "!8BALL")
{
    bot.reply(message, 'Your anwser is: ' + doMagic8BallVoodoo());
}

07-28 06:40