how to make simple telegram user bot?



what is telegram userbot


A Telegram clientbot is a form of robot account that individual consumers utilize rather than clusters or channels. In contrast to standard robots, which are constructed to engage with multiple consumers simultaneously, clientbots prioritize supplying personalized automation and customization choices for individual consumers. Telegram clientbots are erected employing Telegram's Bot API, which grants creators the ability to develop bespoke bots that can dispatch and accept messages, interact with Telegram's API, and accomplish an extensive variety of other duties. Clientbots can automate assignments such as relaying messages, regulating your connections, transmitting reminders, and even participating in games. It is noteworthy that using clientbots is not officially supported by Telegram, and in particular circumstances, could contravene the platform's terms of service. Consequently, it is vital to use clientbots responsibly and within the boundaries of what is sanctioned by Telegram.


what is telethon


Telethon is a Python 3 library based on MTProto that enables interaction with Telegram's API through either a user or bot account (an API option for bots). The library supplies a straightforward interface for creating requests to the Telegram API and getting updates from Telegram. With Telethon, coders can develop bots, userbots, and scripts that interface with Telegram, which are applicable for a variety of intentions like task automation, chatbot creation, and message sending. Telethon can execute a broad range of tasks including sending text, media, files, stickers, and polls, in addition to administering groups, channels, and user accounts. Telethon is an openly accessible library that is actively managed and revised by a community of developers. It supports asynchronous I/O and can be employed with prevalent Python web frameworks, such as Flask and Django. Telethon also contains multiple examples and documentation to aid developers in commencing with utilizing the library.


Create telegram userbot


  1. Install Python and Telethon: Make sure that you have Python 3 installed and then install the Telethon library using pip.
    sudo apt install python3
    pip3 install telethon

     

  2. To connect to Telegram's API, you will need  API ID and hash by following the instructions.
  • Go to telegram.org and log in to your account.
  • Once you're logged in, go to the Telegram API development tools page (https://my.telegram.org/apps).
  • Click on the "Create a new application" button and fill required information. You'll need to provide a name and short name for your application,platform and description
  • Once you've created your application, you'll be redirected to  API ID and hash page.


Example code


from telethon.sync import TelegramClient, events

with TelegramClient('name', api_id, api_hash) as client:
   client.send_message('me', 'Hello, myself!')
   print(client.download_profile_photo('me'))

   @client.on(events.NewMessage(pattern='(?i).*Hello'))
   async def handler(event):
      await event.reply('Hello')

   client.run_until_disconnected()


This is how we can make simple telegram userbot, you can read more here