S
S
Sergey Stadnik2020-05-20 13:36:01
In contact with
Sergey Stadnik, 2020-05-20 13:36:01

Why doesn't random work in VK bot?

const answers = [`тест`,`тесттест`,`ненетест`]
const responseNumber = getRandomIntInclusive(0, 2)
function getRandomIntInclusive(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; }



updates.hear(/тест$/i,(context) => {
let platform = false
if(context.isChat) platform = true
let user = base.bs[base.id[context.senderId].id]
let nick = ``
if(user.nicknotify == false) {
  nick = `${base.bs[base.id[context.senderId].id].nick}`
}
if(user.nicknotify == true) {
  nick = `*id${context.senderId} (${base.bs[base.id[context.senderId].id].nick})`
}
let myclan = clan[base.bs[base.id[context.senderId].id].clan]
  if(context.text.includes(``) && context.messagePayload.command !== `help`) return;
  return context.send({ 
  message: answers[responseNumber]}) 
  })

Why, when I write a "test" to the bot, it gives only the answer number 0, but if I directly write message: getRandomIntInclusive(0, 2), then it gives out random numbers?
I can't solve this problem...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Nedzvetsky, 2020-05-25
@nuriboy

you have the responseNumber value set only once when the script is run, so the bot will always respond with the same

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question