帶有pyTelegramBotAPI的Python Telegram Bot



如果您喜歡該視頻,請務必評論,頂和訂閱。如果您有任何疑問,請將其保留在評論中,我會儘快檢查您。任何建議和/或建設性的批評表示讚賞。

鏈接到官方的Telegram Bot API:https://core.telegram.org/bots/api

鏈接到pyTelegramBotAPI存儲庫:https://github.com/eternnoir/pyTelegramBotAPI

至於我選擇的編輯器,我更喜歡使用完全可定製的開源Atom。鏈接:https://atom.io

在pyTelegramBotAPI中,使用裝飾器函數訪問消息處理程序。如果您不知道這些是什麼,可以看以下一些內容:
代碼船的「 Python裝飾器指南」-https://www.thecodeship.com/patterns/guide-to-python-function-decorators/
Corey Schafer撰寫的「 Python教程:裝飾器」-https://www.youtube.com/watch?v=FsAPt_9Bf3U

我還談到電報如何每小時左右關閉連接,所以這是Github問題:https://github.com/eternnoir/pyTelegramBotAPI/issues/251#issuecomment-278531560

如果您對Lambda函數有困難,可以快速閱讀以下文章:https://pythonconquerstheuniverse.wordpress.com/2011/08/29/lambda_tutorial/

您可以在哪裡免費託管您的機器人(請不要將其用於測試以外的目的):https://pythonanywhere.com

我還聽說您可以在Heroku上託管該機器人,但我個人無法做到這一點。如果您想在實際伺服器上託管該機器人,我建議Scaleway的Starter X86-64價格為2.99英鎊。

如果您需要機器人的代碼,請立即使用它,它是開源的,可以在https://github.com/karipov/atlink上找到。

感謝收看! 。

34 comments
  1. Make a video on how to use force_reply sir. Examples: 1. Bot Ask: Purchase Amount: 2. User Response: (Purchase Input) 3. Then Bot Response: You buy so much (Specifies the purchase amount that a user inputs) how to pack

  2. Hi
    i have some errorse like this
    what is my problem?

    telegram.error.NetworkError: urllib3 HTTPError HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot1131814295:AAG0I7s0n0xu8InJqQLf4hSZeTDlZIEmkHk/getMe (Caused by ConnectTimeoutError(<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x000002769B6DF7F0>, 'Connection to api.telegram.org timed out. (connect timeout=5.0)'))

    I'm in iran and telegram is filtered by government 🙁
    how can I solve my problem?

  3. @Tech Mind
    First of all, thank you for this tutorial. The best so far.
    Could you continue this kind of tutorials related to pyTelegramBotAPI?!

  4. How can i set a auto welcome message and group rules to new joining members to the group. I saw many videos in Youtube with bots (the bot which are created by others), Is there any simply way to set a welcome messages with group rules with a Facebook link with OWN BOT i mean the bot we created.

  5. i have follow your instruction, but when i send a chat to my bot, the bot never answer it.
    Please tell me if there any something to do before or after write your code, please

    import telebot

    import time

    bot_token = 'MyToken'

    bot = telebot.TeleBot(bot_token)

    @bot.message_handler(commands=['help', 'start'])

    def send_welcome(message):

    bot.reply_to(message, "Welcome in Chat Bot !")

    print('Ok No Error');

  6. Very good howto for the beginners, like.
    A little remark on str.format() method.
    You may consider using f-strings for that purpose, it's more readable, check the line 26, timecode 12:33

    bot.reply_to(message, f"https://instagram.com/{at_text[1:]}")

    And a question.
    Could you be more precise on the exception we need to catch? What type of exception is this?

  7. it's giving me an error Traceback (most recent call last):

    File "bot.py", line 6, in <module>

    bot = telebot.TeleBot(token=TOKEN)

    TypeError: __init__() got an unexpected keyword argument 'token'

Comments are closed.