Answer the question
In order to leave comments, you need to log in
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();
})
const st = new HearManager();
st.hear(/^\-(?:help)$/i, ctx => {
var u = users.find(x=> x.id === ctx.senderId)
return ctx.send(`
Вы ${u.name} ввели команду "-help"
`)
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question