We make a Telegram bot with the Admin panel and many other goodies

Hello everyone! Since this is my first article and I do not know what and how to do, I will write as I know.

Today I would like to tell you how easy it is to make your Telegram bot in the very popular Programming Language – Python. The article will be in two parts, in the first we will install Python and all the necessary components and write the simplest bot, in the second we will write the basic logic of the bot. If you are not a beginner, you can scroll down, as there will be a lot of information familiar to you.
I will not torment with a long introduction, let’s get started!

And so the first thing we need to do is draw up a plan for our bot. The plan will include: what functions the bot and everything will perform.

How our bot will look from the user’s side:

  1. The user enters the bot and writes the command “/ start”

  2. Goes to the main bot menu

  3. User selects an action on the keyboard buttons

Fully functional boa does not need to be painted as it will take a very long time and in the future it is useless

Now let’s imagine that you will see you as the Admin and Owner of this bot:

  1. You enter the bot by writing the command “/ start”

  2. You get to the main menu of the Admin panel

  3. Choose an action on the keyboard

This is where our bot plan ends, we proceed to the Python installation part.

  1. We go to the site python.org

  2. Click on the “Download” tab

  3. Scroll to the bottom and download the latest version of Python (at the moment it is Python 3.10)

  4. You will now begin installing the Python Installer. When it downloads open it and you should have a window like this:

    You will have an inscription "Install now", I don't have it since I already have Python downloaded
    You will have an inscription “Install Now”, I don’t have it since I already downloaded Python
  5. Be sure to check the box next to “Add Python 3.10 to PATH”

  6. After installation, it will be possible to disable the length limitation MAX_PATH… Linux systems do not have these restrictions. If you ignore this point, you may face a compatibility problem in the future. Code written on Linux will not run on Windows.

  7. That’s it, you now have Python

Now let’s start installing, but already the library, not the YP

If pip is not installed
  1. Download the file get-pip.py and save it on your computer.

  2. Open a command prompt and navigate to the folder where you saved get-pip.py

  3. At the command prompt, run the command: python get-pip.py or python3 get-pip.py

  4. PIP installed 🎉!

Create a new folder where you will develop the bot

Go to the command line, go through it to the development folder and enter the command to install the aiogram library

pip install aiogram

And let’s finally get to the code:

  1. First, let’s open the Python development environment

    1. IDLE on Windows is located in the “Start“→”Python 3.10“→”IDLE“You can also quickly find it through”Search“near the menu”Start“by typing” IDLE “in the search field:

    2. IDLE has the ability to fully work with files – view, edit, create new ones. To create a new file, select “File” -> “New File” (or Ctrl + N). A new window will open:

    3. Save the file to the folder where we installed the library

    4. Everything is ready to write code

  2. The first thing we need to do is import the libraries.

    import logging # эта библиотека идет вместе с python
    from aiogram import Bot, Dispatcher, executor, types # импортируем aiogram
  3. Next, we declare several variables:

    API_TOKEN = 'ТОКЕН' # Токен 
    logginglogging.basicConfig(level=logging.INFO) # Initialize bot and dispatcher
    bot = Bot(token=API_TOKEN)
    dp = Dispatcher(bot)
  4. Next, we write the first handler for the / start and / help commands

    @dp.message_handler(commands=['start', 'help'])
    async def send_welcome(message: types.Message):
    	await message.reply("Привет! Это простейший бот на aiogram") # отвечает на сообщение
  5. Now we will process each message and send it back.

    @dp.message_handler()
    async def echo(message: types.Message):
    	await message.answer(message.text)
  6. And at the very end we add two lines so that the bot would always work

if __name__ == '__main__':
  executor.start_polling(dp, skip_updates=True)

That’s all, now it remains to get the bot token and insert it into the API_TOKEN variable

Getting a Token for a Bot
  1. Open @BotFather and run it (Start / Start).

  2. In the list of suggested commands, select: /newbot - create a new bot, click on this command, or enter it manually in the field for entering messages.

  3. You will be prompted to indicate the name of the bot, in the future the name of the bot can be changed. Enter a name in the message field.

  4. Next, you will be asked to specify the name by which the bot will be available to users. Write the name using the Latin alphabet, numbers and underscore. Another important condition is that the name must end with “bot”. You can also capitalize “Bot” or “_bot” or “_Bot”.

After these actions, you will receive a message with the bot token

We insert it into the API_TOKEN variable

If you have followed all the steps that are described above, everything will work successfully for you and you are great, but if you have any problems, write to me on Telegram @ derkown

That’s all! Thanks for reading, Part 2 is coming soon. Again, my Telegram is happy to welcome you. Good luck and Goodbye!

Similar Posts

Leave a Reply