如果参与者离开组或新参与者添加到组,为什么电报机器人不起作用?



当我运行我的应用程序,有人在组左或新的参与者加入到组,我的机器人停止工作。

下面你可以看到我的应用程序代码:

const TelegramBot = require('node-telegram-bot-api');
const token = '1928095766:AAGf5aU7E1_FAM_fWzQs3SSGy-1AJS0DjcY';
const bot = new TelegramBot(token, { polling: true });

bot.on('message', async msg => {
const reg = /dd-dd$/;
if (msg.text.match(reg)) {
bot.sendMessage(msg.chat.id, 'Gh')
}

})

当我的应用程序运行时,如果有人离开组或添加新组,我在终端收到的结果:

(node:21155) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined
at TelegramBot.<anonymous> (/Users/romansavka/Telegram-Bot-Node/telegram-bot/reminder.js:11:30)
at TelegramBot.emit (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/eventemitter3/index.js:182:35)
at TelegramBot.processUpdate (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:634:12)
at /Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegramPolling.js:110:22
at Array.forEach (<anonymous>)
at /Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegramPolling.js:106:17
at tryCatcher (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:462:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21155) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:21155) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是因为收到的消息没有属性文本,所以错误引发UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined

最新更新