How To Create A Telegram Bot In Python For Beginners (2023 Tutorial)

Поділитися
Вставка
  • Опубліковано 4 лип 2024
  • In today's video we will be creating a chat bot for Telegram using Bot Father and Python. This is the perfect bot for getting started with creating more complex Telegram bots. It will show you how to get an API Token, how to customise the bot, how you can add commands to the bot, and how you can make it work in groups!
    ▶ Become job-ready with Python:
    www.indently.io
    ▶ Follow me on Instagram:
    / indentlyreels
    00:00 Intro
    00:32 Bot Father
    01:27 API Token
    02:15 Bot Customisation
    04:20 Pip Install
    04:51 Imports
    05:11 Bot Commands
    07:09 Handling Responses
    09:08 Handling Messages
    13:07 Errors
    13:37 Putting It Together
    16:24 Command Descriptions
    18:12 Running The Bot
    19:35 Group Chat
    21:55 Success!

КОМЕНТАРІ • 255

  • @moharrammoharrami3957
    @moharrammoharrami3957 Рік тому +59

    Thanks, today was my off day and I randomly found this video. First I made this exactly as you taught, then I changed stuff and learned more about python (I'm a JS developer). Best way for a software developer to spend his off day :)

  • @worldofelectronicsandprogr1128
    @worldofelectronicsandprogr1128 Рік тому +15

    Awesome tutorial!! ☺☺ I've managed to make my first chat box watching this great and simple video! Many thanks! 👏👏🙏🙏 You are a great tutor and you explain very well the concepts! 👍👍Keep up the good work!!!! ☺☺🙏🙏

  • @yashchatt5754
    @yashchatt5754 2 місяці тому +3

    Was searching for updated vid! This helps a lot

  • @strycinek
    @strycinek Рік тому +11

    Excellent video man, it was exactly what I need to create my own simple bot

  • @humadi2001
    @humadi2001 Рік тому +3

    I keep coming to your source code several times. Keep it up!

  • @auroram4936
    @auroram4936 4 місяці тому +3

    thank you so much for this clear, easy to follow tutorial!! you saved my project

  • @jonnywoo8418
    @jonnywoo8418 Рік тому +2

    Finally Latest version video! Thanks!

  • @sen4674
    @sen4674 Рік тому +2

    Thanks, I just successfully made my first Telegram bot.

  • @chris-mq8rv
    @chris-mq8rv 6 місяців тому +1

    great walkthrough, and explanations along the way. Thanks man.

  • @xasaninomov1453
    @xasaninomov1453 9 місяців тому +1

    Thank you, very much I am so exited that my bot is actually working

  • @systemkey1
    @systemkey1 3 місяці тому

    very excellent video my brother keep up the good work.

  • @ezekiel543
    @ezekiel543 3 дні тому

    This video is very good and the best I found on creating a Telegram bot with Python. Its super easy to understand and follow along.

  • @adityakakade836
    @adityakakade836 5 місяців тому

    Thanks brother. It working. Very informative tutorial 👍

  • @qwert4871
    @qwert4871 10 місяців тому +5

    Great tutorial! There's one thing I want to add though. Your implementation of error handler lacks information on a line of the problem. After passing around with GPT-4 for a while I found a solution to get more information:
    ```python
    async def error(update: Update, context: ContextTypes.DEFAULT_TYPE):
    _, _, tb = sys.exc_info()
    line_number = traceback.extract_tb(tb)[-1][1]
    exc_type, exc_value, exc_traceback = sys.exc_info()
    error_traceback = traceback.format_exception(exc_type, exc_value, exc_traceback)
    print(f"Update {update} caused error {context.error}:
    {''.join(error_traceback)}")
    ```

  • @chaitanyaunavane5819
    @chaitanyaunavane5819 Рік тому

    thank you for the updated video! very helpful

  • @hicamajig
    @hicamajig Рік тому

    Very good overview. Thanks for this!

  • @arsalanshafiq9260
    @arsalanshafiq9260 Рік тому +1

    Really like your accent and sense of humour

  • @charleshu8041
    @charleshu8041 7 місяців тому

    it's amazing I followed your video did the same and it works and running well in my local PC, this my first time learn Python!! thank you so much!!! can you also make another video to show how to deploy these codes to Lambda? One thousand thanks to you🎉❤

  • @YHVB1
    @YHVB1 10 місяців тому

    Very informative video, Thank you!

  • @Juan-wg4gy
    @Juan-wg4gy Рік тому +2

    Hi, how are you?. When I run all the telegram libraries, such as: Filters, it returns me that it is not compatible with version 3.11 of python. But from what I see you are using 3.11, what could be the reason that throws me that error?

  • @nemira_oni590
    @nemira_oni590 Рік тому

    thanks, just inserted my token and bot name and it works!

  • @user-wf4ew5gx1q
    @user-wf4ew5gx1q 9 місяців тому

    thanks for sharing your knowledge

  • @taichinhexpress_official
    @taichinhexpress_official 9 місяців тому

    Thank you so much, i learn and make it successfully. 😍😘

  • @KH-Hi_1XBET1
    @KH-Hi_1XBET1 3 місяці тому

    Love the video it amazing 😍

  • @SlLakshan
    @SlLakshan Рік тому

    Great video. Thank you.

  • @mlindatech
    @mlindatech 6 місяців тому

    Great at first this thing did not work but after revisiting my code it worked

  • @sifiso89
    @sifiso89 8 місяців тому

    BROOOOOOOOOOOOOOOOOOOOOOOO
    thanks a million 🇿🇦

  • @khoreugene3060
    @khoreugene3060 Рік тому +1

    Hi, i love you videos, can you do one that integrate sending photos from certain url once you do a command? and also do one video with inlinekeyboard?

  • @user-lv7ft2zu7k
    @user-lv7ft2zu7k 11 місяців тому

    Nicely done.

  • @__mmars
    @__mmars 10 днів тому

    you're an angel!!!!!!!!!! tysmmm

  • @parsahosseini4241
    @parsahosseini4241 Місяць тому +2

    Clear, to the point, no bs, clean code and understandable instructions.
    This man got himself my respect ❤
    Thanks a lot for this quality content mate.

  • @mayorc
    @mayorc Рік тому +2

    Can you make a video for the updated workflow for telegram bots using login credentials, two factors authentication using OTP, and ConversationHandler using multiple STATES?

  • @lucasputz4475
    @lucasputz4475 2 місяці тому +1

    i love your descriptions like "we'll need a command handler that is handling the commands". you could have just published your code with explanations like that

    • @Indently
      @Indently  2 місяці тому

      I make myself laugh sometimes

  • @user-sc1sm3em9w
    @user-sc1sm3em9w 6 місяців тому

    cool video)

  • @ilkhomjonabdurakhimov8158
    @ilkhomjonabdurakhimov8158 Рік тому

    To create this telegram bot We should use Pycharm Ultimate or it is possible create it by Community version of program?

  • @arsalanshafiq9260
    @arsalanshafiq9260 Рік тому

    Great well done

  • @adeola1183
    @adeola1183 Рік тому +1

    Great video. How would I make one command randomly generate a predefined number of responses?

  • @domontowicz
    @domontowicz Рік тому

    Hi! Thanks for the tutorial! Could you make a video about how to create a bot grabbing messages by keywords from different telegram private channels and sending to our private channel?

  • @MichaelBomett
    @MichaelBomett Рік тому

    Thanks for the video, how do i add the script to a django project so it runs alongside and uses context from django model to respond back? Any pointers?

  • @user-os1hv1lm3l
    @user-os1hv1lm3l 5 місяців тому

    Hello, you are great, I like your teaching very much. Why didn't you post more video for telegram bot in python?

  • @sherminatorhd318
    @sherminatorhd318 Рік тому

    hey man great video, any idea on any platform recommended to run the bot?

  • @John-om5dm
    @John-om5dm 8 місяців тому

    Legend!

  • @appalachhiahuesllc.231
    @appalachhiahuesllc.231 10 місяців тому

    Do you do custom bot builds? I am definitely not this savvy with computers!

  • @mhamadnazm7588
    @mhamadnazm7588 7 місяців тому

    Great tutorial

  • @user-ot5bq2gk8l
    @user-ot5bq2gk8l 11 місяців тому

    thanks for you,you are greate developer.

  • @gulnarahuseynova1718
    @gulnarahuseynova1718 6 місяців тому

    Thank you so much!

  • @liam-gc9zt
    @liam-gc9zt 4 місяці тому +2

    line 24, how would I put that right pointing arrow on linux with nano?

  • @Gautam1108
    @Gautam1108 Рік тому

    I was kind of curious to ask: if I create this bot - will i be able to access data of a website through it's API key? I want to perform an analysis of the data.

  • @wahbi26.
    @wahbi26. 23 дні тому

    thank you, the video is helpful

  • @borismaiorov2703
    @borismaiorov2703 Рік тому

    Hi! Thank you very much! Got it all done, no errors, but when i running the script i getting "Process finished with exit code 0"

  • @-nu6co
    @-nu6co 2 місяці тому

    Well explained

  • @Zynnel
    @Zynnel Рік тому

    Thank you so much this worked perfectly, i just have a question, how can I add emojis to the bot responses?

  • @joshitoshi9835
    @joshitoshi9835 Рік тому +1

    Thanks for the tut but plz teach us with more details about the api, like why we are using or calling this and that function. Plus how can we restrcit access to some users only? like i want 5 people to use the bot only.
    Also teach us how to convert any python script to telegram bot. Thanks

  • @thelostman5625
    @thelostman5625 Рік тому

    Hi! Can we make bot having menu subscribe and when user choose subscribe, the /subscribe menu become /unsubscribe only for the user?

  • @emanuelalbuquerque9032
    @emanuelalbuquerque9032 Рік тому

    Keep up this magnificent work that helps many people who work or want to work with technology. A hug directly from Brazil.

    • @anunareddy2733
      @anunareddy2733 11 місяців тому

      Hello sir!

    • @bhai431
      @bhai431 4 місяці тому +1

      *What is PYTHON SCRYT? How to get that* ?

  • @ramsidharth2931
    @ramsidharth2931 4 місяці тому

    Finally got a legitimate code that would work !

  • @Alexos92
    @Alexos92 7 місяців тому +1

    Amazing video, really great way to get started on a bot project :)
    You cast all your variables into a type. This is not very common in python no ? Will the code work without it ? Thanks for your work !!

    • @whistleblower66
      @whistleblower66 6 місяців тому

      Yes, it will work but I find it's a good practice, in general.

  • @systemkey1
    @systemkey1 3 місяці тому

    thank you SO much.!!

  • @alexandrkardash6594
    @alexandrkardash6594 2 місяці тому

    Thank you for tutorial. Just wonder if you familiar with telegram payments platform? Hopefully you'll find this topic interesting and create amazing short tutorial for that. Thanks you for your work

  • @nikhiljoshi-hk9zu
    @nikhiljoshi-hk9zu 5 місяців тому

    as the bot developer do you have access of the material I sent to the bot, or can the bot spread the material I have sent to it ....pls tell

  • @MrValVet
    @MrValVet 4 місяці тому

    Thank you!

  • @bakousystems3888
    @bakousystems3888 8 місяців тому

    thank you! very helpful. in grouptype show "supergroup" from console

  • @henrynph
    @henrynph 8 місяців тому

    i have a question , i follow your tutoral to coding ,the python can run smothly but the bot can't respont my command which part aer gose wrong?
    also i sen the message when the code run the python out respont the message i send said channel_chat_created=False

  • @user-mq1kb4dc3z
    @user-mq1kb4dc3z 8 місяців тому

    Man,you're cool!

  • @user-sx1uc2sv8c
    @user-sx1uc2sv8c 4 місяці тому

    Would this still work using elif statements rather than if statements?

  • @deep_singh01
    @deep_singh01 5 місяців тому

    Superb Video 🤟🤟
    But Can you please help in building chatbot that answer any question or query automatically in this manner?

  • @worldofelectronicsandprogr1128

    Can you make a video on creating automated welcome messages to new members in a Telegram group? It would be extremely useful! Thanks! ☺☺🙏🙏

  • @zewelry
    @zewelry Рік тому

    thank you. one question,i want run other thing when polling. how to do that.

  • @jacksonjiang6313
    @jacksonjiang6313 11 місяців тому

    Thank you for your very clear explanation. But I am wondering how to purely send a message instead of replying? Coz I don't think it should be added into add_handler. Could you help me to solve that?

  • @user-sp5km5hd4s
    @user-sp5km5hd4s 7 місяців тому

    Did u paste the token on visual code studio or node.js

  • @Misael62.
    @Misael62. Рік тому

    the terminal tell me this. when i write (pip install python-telegram-bot)
    command not found: pip
    What can i do???

  • @hazza6208
    @hazza6208 6 місяців тому +1

    It worked for me. Thank you for the wonderful content. I hope you can explain to us how to put all the languages in artificial intelligence

    • @2mat012
      @2mat012 5 місяців тому

      can you share the code

  • @telmuungan-ulzii8333
    @telmuungan-ulzii8333 11 місяців тому

    What program are you using for coding?

  • @nabil.hamawi
    @nabil.hamawi Рік тому

    Thanks!

  • @lemon-lu3gv
    @lemon-lu3gv 7 місяців тому

    thanks for your video!!!!!!

  • @sontoviet6374
    @sontoviet6374 9 місяців тому

    Hi Admin. How can i do to response user only by one fix message and do not run any command when recever message mode private. Because i only want my bot respond in group. Pls help me

  • @superOify
    @superOify 7 місяців тому

    is there a way to deny other people to communicate with my bot ?
    I tried to create a group with only me and the bot and after that disable /setjoingroups and /setprivacy 'ENABLE', but iam still able, and so is everyone else to write to it

  • @abbosbekpirnazarov
    @abbosbekpirnazarov 2 місяці тому +1

    Hi guys I have a poblem with this | 14:32 | (custom_command) What should I do ?

  • @touhami_dz6458
    @touhami_dz6458 4 місяці тому

    what wallpaper are you using on ur desktop ? i like it

  • @farshadpanahi4384
    @farshadpanahi4384 Рік тому

    خیلی هم خوب. ادامه بده.

  • @brianngoh4461
    @brianngoh4461 11 місяців тому

    hi i've been getting this error and I cant really find anything on google
    AttributeError: 'ApplicationBuilder' object has no attribute 'add_handler'

  • @xasaninomov1453
    @xasaninomov1453 9 місяців тому +1

    help me a have some kind wierd situstion it says 'import 'telegram' not found'

  • @SemiColonCoder
    @SemiColonCoder Рік тому

    Hi How to make a video response or a file response other than string?

  • @CryptoSaNjAY1
    @CryptoSaNjAY1 6 місяців тому

    How to Create a bot without joining the source group it will forward messages to the designation group is it possible?

  • @richardogundele6437
    @richardogundele6437 Рік тому

    this is the error i am getting in running the code ImportError: cannot import name 'Update' from partially initialized module 'telegram' (most likely due to a circular import)

  • @kamilkoterba9368
    @kamilkoterba9368 8 місяців тому +1

    Hey man im pretty Newbie to programming, what i must do to have Python set up like You? As i download it and it doesent look the same the tabs below and the line numbers, Cheers!

  • @jamesacquaye8054
    @jamesacquaye8054 Рік тому

    Hi please how do I get the pip install command using pycharm

  • @zvim4664
    @zvim4664 Рік тому +4

    Can somebody help me when i type % pip install python-telegram-bot in terminal i get this: You cannot call a method on a null-valued expression. Im stuck here for an hour cant find a solution help

    • @v3ng4r65
      @v3ng4r65 8 місяців тому

      You have to get PATH in Windows for Phyton

  • @bikrantjajware6062
    @bikrantjajware6062 10 місяців тому

    How do we add users to a group chat if i have usernames/ user_ids

  • @user-sb6jt5yr5h
    @user-sb6jt5yr5h 6 місяців тому

    hello i want to ask something, why the bot always replying every message I've already activate the response only when it get mention, can anyone explain it?

  • @viralquotes1105
    @viralquotes1105 Рік тому

    Hello! The bot was completed and run successfully but not respond in telegram any help please

  • @MrAtomUniverse
    @MrAtomUniverse Рік тому

    I cant seem to get the Menu button to show up , any idea why ?

  • @abjoke
    @abjoke Місяць тому

    Guys I'm facing a problem. When I write the code "from telegram import update" the telegram word shows the error " could not be resolved by pylance. " I already installed and even updated telegram bot by pip but still not working. I need some assistant.

  • @revinanatasari6274
    @revinanatasari6274 7 місяців тому

    hi i cant seem to import telegram and the telegram.ext :( what should i do

  • @scotter
    @scotter 8 місяців тому +1

    Thanks for this! I got it working the first time. THANK YOU! Wondering if you can help with one issue: In supergroups it responds to everyone. I tried merely adding "or 'supergroup' in ..." but that didn't work. Also, issues getting user id or username. Telegram's page on their API is either old or just difficult for me to figure out. Any help welcome!

  • @abdulwahidali493
    @abdulwahidali493 5 місяців тому

    thank you

  • @LokeshWankhede
    @LokeshWankhede Рік тому

    Your wallpaer is really cool! Can I get one?

  • @sudharsandas5779
    @sudharsandas5779 Рік тому +1

    Is the explicit typing necessary in Python? Why is he doing this?

  • @teenu3670
    @teenu3670 Рік тому +1

    this bot is replying to anyone if the user is not even mentioning the bot in group
    how to fix

  • @Ayoubased
    @Ayoubased Рік тому

    why we need to start with botfather, is this the native way of making bots in telegram?