I
I
Ivan Trofimov2020-12-29 21:16:30
JavaScript
Ivan Trofimov, 2020-12-29 21:16:30

How to do asynchronous user registration?

Let's get right down to business:
I made a reg. user, this does not work when the user writes any command. (which is in the bot: -help ....)
(PS: If the user is not registered and only wrote for the first time).

This goes to the console: ReferenceError: u is not defined

User registration code:

vk.updates.use(async (ctx, next) => {
        if(ctx.isGroup) return;
        var id = Number(ctx.senderId);

  if(id === undefined || Number.isNaN(id)) return;

  if(!users.find(x=> x.id === id)){
    var [f] = await vk.api.users.get({user_id: id});
    var data = new Date();

    users.push({
      id: id,
      uid: users.length + 1,
      name: `${f.first_name} ${f.last_name}`,
      nick: f.first_name
    });
  }

  await next();
})


Command code "-help":
const st = new HearManager();

st.hear(/^\-(?:help)$/i, ctx => {
var u = users.find(x=> x.id === ctx.senderId)

return ctx.send(`
Вы ${u.name} ввели команду "-help" 
`)
})


(I don't know if it's allowed to post a link to pastebin.com here)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question