DigitalOcean Referral Badge
Udit Vashisht
Author: Udit Vashisht

How to create a Telegram Bot using Python?

  • 2 minutes read
How to create a Telegram Bot using Python?

    Table of Contents

Create a Telegram Bot using Python

In this article, we will learn to create a simple telegram bot using python. First of all, we will create the API token for our telegram bot.

Connect with FatherBot

We can do this by opening the BotFather bot on telegram. Yes, we will be using a bot created by Telegram to start creating our own Bot. For this, you must have telegram installed on your machine. If you have it already installed, click on this link to start with. This will open a new Telegram Bot chat and clicking on ‘start’ will give you the following screen.


Create a new bot using the Father Bot.

Now send /newbot message to the Fatherbot and choose your bot’s name and user name and you will get your API and copy it.


Code your first Telegram Bot in Python

Now, we will quickly jump to the coding part of this tutorial. It is convenient to use a virtual environment (Blogpost/Video) for your project and we would be using python-decouple to save our token key securely instead of hard coding it in the code itself.

Once, you have created a desired folder and activated the virtual environment, you can install the requisite modules using the following command

pip install pyTelegramBotAPI python-decouple

Once, this is done, create a new .env file in the same folder, open it in your favorite editor and add your api-key in it:-


Now, create a new python file and start coding

import telebot
from decouple import config

#getting the key from .env file
API_KEY = config('API')

#creating the bot

bot = telebot.TeleBot(API_KEY)

#passing the 'hello' command to the bot


#getting the bot to output "Hello!"

def hello(message):
    bot.send_message(, "Hello! I am a bot created by SaralGyaan")

#looking out for messages

The code above is self explanatory, now run the python file to start the bot and then open telegram on your phone or device and search for your bot with name or id which you created. For me, it is saralgyaan-bot or saralgyaan_bot. Send ‘/hello’ to your bot to get the reply


Related Posts

Chapter 4 - Print function
By Udit Vashisht

How to use Python print() function?

In the early days of your python learning, one function that you are going to use the most is the print() function. So, I have decided to add it in the opening chapter of this tutorial. In addition to the print function, you ...

Read More
Pie Charts in Python | Matplotlib Tutorial in Python | Chapter 3
By Udit Vashisht

Matplotlib Tutorial in Python

Chapter 3 | Creating Pie Charts in Python

In this chapter, we will learn to create Pie Charts in Matplotlib in Python. Pie Charts are an intiutive way of showing data, wherein each category is shown as a portion of the pie. Let ...

Read More
How to append to a list in Python ? - Python List append() method
By Udit Vashisht

Python List append() method

The Python list append() method adds an item to the end of the list. The length of the list increase by one.

Syntax of append()

The syntax for the same is :-


Parameters of append()

The method takes only a single argument


Read More
tech tutorials automate python beautifulsoup web scrapping webscrapping bs4 Strip Python3 programming Pythonanywhere free Online Hosting hindi til github today i learned Windows Installations Installation Learn Python in Hindi Python Tutorials Beginners macos installation guide linux SaralGyaan Saral Gyaan json in python JSON to CSV Convert json to csv python in hindi convert json csv in python remove background python mini projects background removal tweepy Django Django tutorials Django for beginners Django Free tutorials Proxy Models User Models AbstractUser UserModel convert json to csv python json to csv python Variables Python cheats Quick tips == and is f string in python f-strings pep-498 formatting in python python f string smtplib python send email with attachment python send email automated emails python python send email gmail automated email sending passwords secrets environment variables if name == main Matplotlib tutorial Matplotlib lists pandas Scatter Plot Time Series Data Live plots Matplotlib Subplots Matplotlib Candlesticks plots Tutorial Logging unittest testing python test Object Oriented Programming Python OOP Database Database Migration Python 3.8 Walrus Operator Data Analysis Pandas Dataframe Pandas Series Dataframe index pandas index python pandas tutorial python pandas python pandas dataframe python f-strings padding how to flatten a nested json nested json to csv json to csv python pandas Pandas Tutorial insert rows pandas pandas append list line charts line plots in python Django proxy user model django custom user model django user model matplotlib marker size pytplot legends scatter plot python pandas python virtual environment virtualenv venv python python venv virtual environment in python python decorators bioinformatics fastafiles Fasta python list append append raspberry pi editor cron crontab Cowin Cowin api python dictionary Python basics dictionary python list list ios development listview navigationview swiftui ios mvvm swift environmentobject property wrapper @State @Environm popup @State ios15 alert automation instagram instaloader texteditor youtubeshorts textfield multi-line star rating reusable swift selenium selenium driver requests-html youtube youtube shorts python automation python tutorial algo trading nifty 50 nifty50 stock list nifty50 telegram telegram bot dictionary in Python