yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.13k stars 1.49k forks source link

How can i stop listening for a specific user onText message? #1103

Closed m0x61h0x64i closed 11 months ago

m0x61h0x64i commented 11 months ago

Hello, i want to stop listening for '/start' command when the user enters '/start', i have tried bot.removeTextListener(/\/start/) but this will remove listening for all users, i only want to stop listening for a specific user, how can i do this ?

my code is :

bot.onText(/\/start/, async (msg) => {
    console.log('start listener is working...')
    bot.removeTextListener(/\/start/)
})
VDS13 commented 11 months ago
var users = new Map();
bot.onText(/\/start/, (msg) => {
    if (users.get(msg.chat.id) === 'undefined') {
        //first "start"
        users.set(msg.chat.id, 1)
        //...
    } else {
        //...
    }
})