-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How work listener #98
Comments
I do not really understand what you mean. Can you give some sample code? |
Sorry for my bad English. This bot repeat all messages: def listener(messages)
for m in messages:
if m.content_type == 'text':
bot.send_message(m.chat.id, m.text)
if __name__ == '__main__':
bot = telebot.Telebot(config.token)
bot.set_update_listener(listener)
bot.polling(none_stop=True) If start first time bot repeat all mesages, but second time not repeated messages. |
You need add infinite loop after polling. Because polling do not block your thread. So you need block it to avoid thread terminate. Try this. def listener(messages)
for m in messages:
if m.content_type == 'text':
bot.send_message(m.chat.id, m.text)
if __name__ == '__main__':
bot = telebot.Telebot(config.token)
bot.set_update_listener(listener)
bot.polling(none_stop=True)
import time
while True:
time.sleep(1) |
Thank you, just i want to know where store last_update_id, because where we restarting bot dont repeted already repeated messages. Or maybe last_update_id statment calculate in init.py? |
Yes, last_update_id is store in init.py telebot instance. New telebot instance created the last_update_id will be set to 0. When telebot get new messages, it will change last_update_id to max number which new message telebot received.
Do you mean when you restart bot it will not get messages which already get before? Because when telebot call getUpdates with telegram bot api it will pass offset parameters. About this parameters meaning you can find in telegram bot api document. |
Hello, i'am beginner programmer and i want to know which logs read messages. Because when restart script, bot ignore reading messages
The text was updated successfully, but these errors were encountered: