I am developing a telegram bot following the tutorial and the code is working as I want. But there is a warning.
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
I found a solution via stackoverflow.
require('events').EventEmitter.defaultMaxListeners = 15;
I understand that removing the restriction will remove the warning, but not the cause, and you will not receive any alerts about the cause of the resource leak. But I can’t know the reason in my code.
This is my code:
const { Bot, InlineKeyboard } = require("grammy");
// Create a bot using the Telegram token
const bot = new Bot(process.env.HTTP_API_TOKEN || "");
const introductionMessage = `Hello! Welcome to Bot`;
const aboutUrlKeyboard = new InlineKeyboard();
aboutUrlKeyboard.row().webApp(
"Play",
"https://www.google.com/"
);
const replyWithIntro = (ctx) =>
ctx.reply(introductionMessage, {
reply_markup: aboutUrlKeyboard,
parse_mode: "HTML",
});
// Keep this at the bottom of the file
bot.command("start", replyWithIntro);
bot.command("help", replyWithIntro);
bot.on("message", replyWithIntro);
bot.start();