Answer the question
In order to leave comments, you need to log in
I can't make a Node JS timer, how to do it?
in general, the essence of the script is as follows, it must respond in a conversation to the messages of the user whose ID is indicated in the script with text from a text document. I was able to implement this, but I can’t make a timer for the answer, for example, a person wrote any word and the bot should answer him after a certain time and not immediately or randomly in time to pretend as if a person is writing (something like an answering machine) help me do it, I will be grateful))) And if you also help to make it look like a person prints using the messages.setActivity method, then you will not have a price))
const { VK, keyboard } = require('vk-io');
const vk = new VK();
const rq = require("prequest");
const { api } = vk;
const fs = require("fs");
const acc = require("./base/acc.json");
var ls_arr = fs.readFileSync('ls.txt').toString().split("\n");
vk.setOptions({ token: 'сюда токен'});
const { updates, snippets } = vk;
updates.startPolling();
console.log(`Хелло Ворлд`)
updates.on('message', async (message) => {
if(message.senderId == 581661789) return;
var a = message.senderId;
if(a == сюда айди жертвы без скобок)
{
acc.ls++;
console.log(acc.ls);
return message.reply(ls_arr[acc.ls%ls_arr.length]);
}
});
setInterval(function(){
fs.writeFileSync("./base/acc.json", JSON.stringify(acc, null, "\t"))
}, 3500);
Answer the question
In order to leave comments, you need to log in
Before sending, call the api method messages.setActivity, which will last 10 seconds.
Further:
setTimeout(() => {
message.reply("Ответ");
}, Math.floor(Math.random() * Math.floor(10))); // Рандомное число от 0 до 10
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question