D
D
Dmitry Maksimyuk2020-05-27 11:00:39
In contact with
Dmitry Maksimyuk, 2020-05-27 11:00:39

What is this "Cannot read property '1' of undefined" error on Node JS?

I'm making a game bot in VK and in order to withdraw extra funds from the project, I need to make a casino, but I just don't understand why it doesn't work...

vk.updates.hear(/^(?:казино)\s?(.*)?/i, async (message, args, bot, next) => {
  var id = await find(message.senderId);
  message.args[1] = message.args[1].replace(/(\.|\,)/ig, '');
  message.args[1] = message.args[1].replace(/(к|k)/ig, '000');
  message.args[1] = message.args[1].replace(/(м|m)/ig, '000000');

  if(!Number(message.args[1])) return;
  message.args[1] = Math.floor(Number(message.args[1]));

  if(message.args[1] <= 0) return;

  if(message.args[1] > users[id].balance) return message.send(`у вас нет данной суммы`);
  else if(message.args[1] <= users[id].balance)
  {
    users[id].balance -= message.args[1];
    const multiply = utils.pick([0.75, 0.75, 2, 0.75, 0.75, 0.5, 0.75, 0.75, 0.75, 0.75, 0.75, 0.25, 0.75, 0.75, 0.75, 2, 0.75, 5, 0.75, 0.5, 0.75, 0.75, 0.75, 0.75, 0.75, 0.25, 0.75, 2]);

    users[id].balancee += Math.floor(message.args[1] * multiply);
    return message.send(`${['','', '', '', ''].random()} >> ${multiply === 1 ? `Ваши деньги остаются при вас!` : `${multiply < 1 ? `Вы проиграли ${utils.sp(message.args[1] * multiply)}₽` : `Вы выиграли ${utils.sp(message.args[1] * multiply)}₽`}`}
    ❤ >> Сумма умножена в x${multiply}		
     Ваш баланс: ${utils.sp(users[id].balance)}₽`);
  }
});

When you enter the command: casino "number" - it gives the following: 5ece1bef20a6a175068184.jpeg
Perhaps the error is super obvious ... But I've only been studying js for 2 days, I just don't understand what it could be! And it's not about the English language :) I wouldn't lie, I've been sitting on this team for 7 hours, just imagine how many times I rewrote it up and down. And I’ll note that it works in another bot, but for some reason I don’t ... and I have vk.updates.hear and cmd.on in another bot, but I still can’t understand why, because there is only one npm package. vk-io. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Didenko, 2020-05-27
@Dasslier

You get the 1st index from undefined

message.args[1] = message.args[1].replace(/(\.|\,)/ig, '');

For example this line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question