-1

How can I select a random value from this array using JavaScript for discord bot?

var a = [ "lekh","lol"];

bot.on('message', msg=> {
    if(msg.content == "kilka" ){
        msg.reply( Math.floor(Math.random() * a.length ));
    } 
})
socrateisabot
  • 837
  • 2
  • 10
  • 28

1 Answers1

0

You should change: msg.reply( Math.floor(Math.random() * a.length )); to msg.reply(a[Math.floor(Math.random() * a.length)]); to actually select the item from the a array

dako
  • 1,081
  • 1
  • 12
  • 22