skip to Main Content

I am working on creating a telegram bot, I want to make an anti-spam system, that is, when a person presses a button too many times, the bot will freeze for him for a certain number of seconds, it is possible to write a message about blocking. People in other matters do not help me.

import {
    bot
} from '../token.js';

import {
    keyboardMain
} from '../keyboards/keyboardsMain.js';

export function commands() {
    bot.on('message', msg => {
        const text = msg.text;
        const chatId = msg.chat.id;

        if (text === '/start') {
           return bot.sendMessage(chatId, 'hello', keyboardMain);
        }

        return bot.sendMessage(chatId, 'error');
    });
}

2

Answers


  1. Do you use telegraf as telegram module ? If yes, you can kick users from channels or groups.

    Login or Signup to reply.
  2. here is a little piece that i made for you 🙂
    you can apply it to anything ^_^

    var tps = 0;
    var allowpassage = false;
    var detectspamon = document;
    c = function() {
        setTimeout(()=>{
            console.log("got clicks:",tps);
            if (tps==0) {console.log("no clicking detected");}
            else if (tps==1) {console.log("success");allowpassage=true;}
            else {console.log("too many clicks per second");}
            tps=0;
            console.log("setting clicks to 0");
        },500);
    }
    
    detectspamon.onclick = () => {tps++;console.log(tps);c(tps);}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search