-2

I am trying to output a random sentence from a list and then output it as text. How do I do that? Currently I have this code:

if(message.content.startsWith('!')){
   let sentenc = Array('Hello', 'Whats Up')
   shuffle(sentenc)
   messages.channel.send(sentenc)
}

But it doesn't work

DenverCoder9
  • 271
  • 1
  • 10
Spatzl HD
  • 15
  • 4

2 Answers2

0

You could try this:

if(message.content.startsWith('!')){
    let sentenc = ['Hello', 'Whats Up', '2', '3', '4']
    let random = Math.floor(Math.random() * sentenc.length) // Gives you a random position number from 0 to your Array length
    message.channel.send(sentenc[random]) // Sends a message of your Array while random is always between 0 and your Array length
}

See the Math.random() documentation.

snpz
  • 153
  • 10
0

I think you want to shuffle the array and then join the array with spaces in between.
Look at this thread on how to shuffle an array and joining it with spaces is simply done by array.join(" ").

Antoni
  • 356
  • 5
  • 17