简体   繁体   中英

How to remove in node-telegram-bot-api only the bot.on() function?

How can I just remove the bot.on () in order to rerun the bot.onText ()? Because if I do bot.removeListener ('message') it also removes the bot.onText ()

       bot.onText(/\/login/, (msg) => {

                  bot.on('message', (msg) => {
                        //do some stuff
                        bot.removeListener('message');
                  });

       });

Second argument, should be a function of your listener. Fe:

let handler = (msg) => {
  let chatId = getChatId(msg);
  bot.sendMessage(chatId, "Login");
  bot.removeListener("message", handler);
};

bot.onText(/\/login/, msg => {
  bot.on("message", handler);

  bot.on("message", msg => {
    let chatId = getChatId(msg);
    bot.sendMessage(chatId, "Another listener");
  });
});

As you can see, the first time both listeners work, on the second attempt to enter something, only the second listener works.

enter image description here

tbh right now i have the same exact problem and i can't figure it out... smh enter image description here

enter image description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM