yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.43k stars 1.53k forks source link

Getting Polling Error!! #943

Closed xydv closed 2 years ago

xydv commented 2 years ago

I Am Getting This Issue, I Tried Many Times!!

bot.js ⬇

require('dotenv').config();
const TOKEN = process.env.BOT;
const TB = require('node-telegram-bot-api');
const bot = new TB(TOKEN, { polling: true });
const handler = require("./handler/handler")
bot.on('message', (message) => {
    handler(message);
});

handler.js ⬇

const handler = (message) => {
    console.log(message);
    bot.sendMessage(message.chat.id, "Message Recieved");
}
module.exports = handler;

Terminal ⬇ image

Look Into It And Give Suggestions If I Made Mistake!!.

danielperez9430 commented 2 years ago

Hi @icancodebeauty for get better error messages put this line of code:

bot.on('polling_error', (err) => console.log(err));

xydv commented 2 years ago

Shows Error Like This 👇

node-telegram-bot-api deprecated Automatic enabling of cancellation of promises is deprecated.
In the future, you will have to enable it yourself.
See https://github.com/yagop/node-telegram-bot-api/issues/319. node:internal/modules/cjs/loader:1101:14
{
  message_id: 62,
  from: {
    id: ▒▒▒▒▒▒▒▒▒▒,
    is_bot: true,
    first_name: 'Group',
    username: 'GroupAnonymousBot'
  },
  sender_chat: {
    id: -▒▒▒▒▒▒▒▒▒▒▒▒,
    title: 'Yojana Ke Faltu Log',
    type: 'supergroup'
  },
  chat: {
    id: -▒▒▒▒▒▒▒▒▒▒▒▒,
    title: 'Yojana Ke Faltu Log',
    type: 'supergroup'
  },
  date: 1645503673,
  text: '/quote@dedomilbot',
  entities: [ { offset: 0, length: 17, type: 'bot_command' } ]
}
ReferenceError: bot is not defined
    at handler (/workspace/telegram-bot/handler/handler.js:3:5)
    at TelegramBot.<anonymous> (/workspace/telegram-bot/bot.js:7:5)
    at TelegramBot.emit (/workspace/telegram-bot/node_modules/eventemitter3/index.js:182:35)
    at TelegramBot.processUpdate (/workspace/telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:635:12)
    at /workspace/telegram-bot/node_modules/node-telegram-bot-api/src/telegramPolling.js:110:22
    at Array.forEach (<anonymous>)
    at /workspace/telegram-bot/node_modules/node-telegram-bot-api/src/telegramPolling.js:106:17
    at tryCatcher (/workspace/telegram-bot/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/workspace/telegram-bot/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/workspace/telegram-bot/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/workspace/telegram-bot/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/workspace/telegram-bot/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/workspace/telegram-bot/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/workspace/telegram-bot/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/workspace/telegram-bot/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/workspace/telegram-bot/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (node:internal/timers:464:21)

I am hiding my chat id and user id for privacy!!

DesnLee commented 2 years ago

Your handler.js has no the bot instance but used bot.sendMessage

xydv commented 2 years ago

Yes! But How I Add Bot Instance In handler.js?

xydv commented 2 years ago

Its Done Now, I Didn't Send Bot Instance To Handler!!, Thanks To All!!