Questions tagged [telethon]

Telethon is a Python 3 Telegram client library. It uses the normal Telegram API instead of the Bot API, which means it can perform all actions a regular user can perform. Use this tag when asking questions about using the Telethon library.

Python 3 Telegram client library which is used API of Telegram.

Home page: https://pypi.python.org/pypi/Telethon

1211 questions
24
votes
3 answers

Telegram get chat messages /posts - python Telethon

I am using Telethon and Python 3.6xx Been able to retreive message from groups, no problem but when it comes to channels I am stuck. dialogs = client(get_dialogs) for chat in dialogs.chats: getmessage = client.get_messages(chat.id, limit=400) …
AbeeCrombie
  • 597
  • 1
  • 5
  • 22
16
votes
1 answer

How to correct " 'coroutine' object has no attribute 'data'" Error when using Telethon for Telegram?

I am trying to code a simple thing in Python to automatically download some media from a Channel on Telegram. I am using Telethon for this. I keep getting an error that I cannot solve and for which I do not understand the reason. "'coroutine' object…
DDDYlan
  • 189
  • 1
  • 2
  • 7
13
votes
3 answers

AttributeError in pytest with asyncio after include code in fixtures

I need to test my telegram bot. To do this I need to create client user to ask my bot. I found telethon library which can do it. First I wrote a code example to ensure that authorisation and connection works and send test message to myself (imports…
Andrei Alekseev
  • 367
  • 3
  • 9
13
votes
6 answers

How to get all users in a telegram channel using telethon?

I'm new to telethon and python. I have installed telethon in python3 and I want to get all members of a telegram channel or a group . I was searching a lot in the internet and found below code . And I'm trying really hard to understand it .Telegram…
lasan
  • 365
  • 2
  • 5
  • 13
9
votes
3 answers

RuntimeError: Task got Future attached to a different loop

How to call async method which get event loop in main thread inside another async method in Quart? t.py from telethon import TelegramClient, functions, types client2 = TelegramClient(sn, api_id, api_hash).start() async def create_contact(): …
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
9
votes
1 answer

How to use telethon in a thread

I want to run a function in background. so I use Threading in my code. but return error ValueError: signal only works in main thread and don't know about two things: what is the main thread how to solve this problem :) views.py def…
Ehsan
  • 604
  • 7
  • 21
8
votes
1 answer

How to get list of channels that i joined in telethon?

I want to make a script that shows the channels that i joined and then leave all of it with this example: from telethon.tl.functions.channels import LeaveChannelRequest await client(LeaveChannelRequest(input_channel))
amir
  • 143
  • 3
  • 10
8
votes
2 answers

Telethon leads to `RuntimeWarning: coroutine 'MessageMethods.send_message' was never awaited`

I'm trying to run this first code snippet provided by the Telethon documentation. But, after multiple problems (here and here), I ended up with this modified version: import os import sys from telethon.sync import TelegramClient, events # import…
Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
8
votes
1 answer

How forward message to other contact with telethon

How do I forward a message to another chat as soon as I receive it from a contact? I created this example just to test routing, but it doesn't work. #!/usr/local/bin/python3 from telethon import TelegramClient, events api_id = 9999900 api_hash =…
8
votes
1 answer

Telethon, how to get an entity?

I started using Telethon to integrate a python app with telegram API. I was able to get it started and send a few messages. The function for sending messages gets an entity as the first argument. So far I was getting this entity from the…
apadana
  • 13,456
  • 15
  • 82
  • 98
7
votes
3 answers

How to get a telegram private channel id with telethon

Hi can't figure out how to solve this problem, so any help will be really appreciated. I'm subscribed to a private channel. This channel has no username and I don't have the invite link (the admin just added me). Since I use this channel at work, to…
DylanStenico
  • 71
  • 1
  • 1
  • 6
7
votes
1 answer

Sending Telegram messages with Telethon: some entity parameters work, others don't?

I'm using Telethon's send_message function to send messages to various chats. Sometimes, the destination is another user (just a regular one on one chat), sometimes a group, sometimes a supergroup, and sometimes a channel (of which I'm admin). If I…
RocketNuts
  • 9,958
  • 11
  • 47
  • 88
7
votes
4 answers

Add new contact in API telegram Python telethon

How do I save a number in my contacts in telethon Python? from telethon import TelegramClient from telethon.tl.functions.contacts import GetContactsRequest from telethon.tl.types import InputPeerUser client = TelegramClient('arta0', api_id,…
netdevil
  • 309
  • 1
  • 7
  • 18
6
votes
2 answers

How Can I download media to specific path on Telethon

I'm working on telethon download_media and _download_document methods for downloading media from telegram. My code is something like this: from telethon import TelegramClient api_id = 12345 api_hash = '0123456789abcdef0123456789abcdef' client =…
1
2 3
80 81