2017-09-28 67 views
-4

我正在制作不和谐的机器人的过程中,我想知道如何才能做出一个命令,选择一个随机的文本行并输出它?选择随机线并输出它

我想要一个类似于此的命令。另外,我知道的C#

Commands[ "Joke" ] = { 
    oplevel:0, 
    allowed_channels: 'all', 
    allowed_servers: 'all', 
    cooldown: 'none', 
    fn: function(bot, params, msg, msgServer, serverRoles, authorRoles) { 
    var answers = []; 
    answers.push({ 
     message: "Q: What does a dum call a dumpster? A: Bed and Breakfast" 
    }) 
    answers.push({ 
     message: Q: What did the doughnut say to the loaf of bread? A: If I had that much dough, I wouldn't be hanging around this hole." 
    }) 

    answers.push({ 
     message: "What does a dum call a dumpster. Bed and Breakfast" 
    }) 
    answers.push({ 
     message: "Q: What did the doughnut say to the loaf of bread? A: If I had that much dough, I wouldn't be hanging around this hole." 
    }) 
    answers.push({ 
     message: "Q: What do you call cheese that isnt yours? A: Nacho cheese" 
    }) 
+1

欢迎SO。本网站不是代码编写服务,不适用于提供完整的解决方案。预计用户将展示一些努力和代码,而SO在此期间将帮助您解决具体的编程问题。你有没有尝试过任何东西?请阅读:https://stackoverflow.com/help/asking –

回答

1

的基础知识可以做这样的事情:

int index = random.Next(answers.Count); 
var answer = answers[index]; 
return answer;