import asyncio
from telethon import Client, events
from telethon.events import filters
async def main():
async with Client('name', api_id, api_hash) as client:
me = await client.interactive_login()
await client.send_message(me, f'Hello, {me.name}!')
@client.on(events.NewMessage, filters.Text(r'(?i)hello'))
async def handler(event):
await event.reply('Hey!')
await client.run_until_disconnected()
asyncio.run(main())
Are you new here? Jump straight into Installation!
Looking for the Client API reference? See the Client class.
Did you upgrade the library? Please read Changelog (Version History).
Coming from Bot API or want to create new bots? See HTTP Bot API vs MTProto.
Used Telethon before v2.0? See Migrating from v1 to v2.
Want to hack away with the raw API? Search in Telethon Raw API.
Preface
What is this?
Telegram is a popular messaging application. This library is meant to make it easy for you to write Python programs that can interact with Telegram. Think of it as a wrapper that has already done the hard work for you, so you can focus on developing an application.
How should I use the documentation?
This documentation is divided in multiple sections. The first few sections are a guide, while others contain the API reference or a glossary of terms. The documentation assumes some familiarity with Python.
If you are getting started with the library, you should follow the documentation in order by pressing the “Next” button at the bottom-right of every page.
You can also use the menu on the left to quickly skip over sections if you’re looking for something in particular or want to continue where you left off.
First steps
In this section you will learn how to install the library and login to your Telegram account.
Concepts
A more in-depth explanation of some of the concepts and words used in Telethon.
API reference
This section contains all the functions and types offered by the library.
Development resources
Tips and tricks to develop both with the library and for the library.