This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is how I run my new bots created with pyTelegramBotAPI to avoid API errors, | |
like timeout errors or whenever my server can't reach Telegram servers (i.e. if net is down). | |
A while loop restarts the polling when it's ended due to an error. | |
A new bot object is created in each new loop execution, to avoid some errors. | |
We set all our message handlers in botactions() so the new bot object can use them. | |
Threading is not needed, but I prefer running the while True loop threaded so I can stop the bot | |
anytime with Ctrl+C, otherwise it can't be stopped easily. Killing the script is not nice and | |
I use databases in some bots, which should be closed beforehand. |