eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.02k stars 2.02k forks source link

process_new_updates() doesn't work when its fed the updates list got from get_updates() #2191

Closed CarlosBueno99 closed 6 months ago

CarlosBueno99 commented 6 months ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using? % pip freeze | grep pyTelegramBotAPI pyTelegramBotAPI==4.16.1

  2. What OS are you using? macOS 14.3.1 on MacBook Air m2

  3. What version of python are you using? 3.12.2

Here's an example of my test script:

@bot.message_handler(commands=['start', 'hello'])
def send_welcome(message):
    bot.reply_to(message, "Howdy, how are you doing?")

@bot.message_handler(func=lambda message: True)
def echo_message(message):
    bot.reply_to(message, message.text)

print(bot.get_me().first_name)

updates_list = bot.get_updates()
print("type of the update list returned by bot.get_updates():",type(updates_list))

print('type of each update in the list')
for update in updates_list:
    print(type(update), update.update_id)

bot.process_new_updates(updates_list)

Here's the output when I run that file:

BuenoBotTest
type of the update list returned by bot.get_updates(): <class 'list'>
type of each update in the list
<class 'telebot.types.Update'> 862015394
<class 'telebot.types.Update'> 862015395
<class 'telebot.types.Update'> 862015396
<class 'telebot.types.Update'> 862015397
<class 'telebot.types.Update'> 862015398
<class 'telebot.types.Update'> 862015399

Everything works fine if I use bot.infinity_polling() instead.

Badiboy commented 6 months ago

What do you mean under "doesn't work"?

CarlosBueno99 commented 6 months ago

it exits the program as if it ran as expected... but none of the updates are handled and none of the messages are replied on the Telegram conversation.

coder2020official commented 6 months ago

maybe there is a reason for that.

Badiboy commented 6 months ago

I checked. Set "threaded" to False and it will work.

bot = telebot.TeleBot("xxx", threaded=False)