[英]How to remove in node-telegram-bot-api only the bot.on() function?
我怎樣才能刪除 bot.on () 以重新運行 bot.onText ()? 因為如果我做 bot.removeListener ('message') 它也會刪除 bot.onText ()
bot.onText(/\/login/, (msg) => {
bot.on('message', (msg) => {
//do some stuff
bot.removeListener('message');
});
});
第二個參數,應該是你的聽眾的 function。 鐵:
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");
});
});
如您所見,第一次兩個偵聽器都工作時,第二次嘗試輸入內容時,只有第二個偵聽器工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.