from telethon import TelegramClient
bot = TelegramClient(...)
last_id = 0
batch_size = 100
all_messages = []
while True:
ids = list(range(last_id, last_id + batch_size))
messages = await client.get_messages(entity, ids=ids)
if not messages:
break
all_messages.extend(messages)
last_id = messages[-1].id + 1
await asyncio.sleep(5)
this class is for decomposing complex numbers using Pollard's Rho algorithm
code changes reduce the time in calculations
also this was one of way to make calculations faster, we could use GMPY2 library but it is excessive for such a small scale
To see which methods in the library it affects, please search for the class name in the GitHub repository
Hi, I was engaged in inviting users on my channel through the "InviteToChannelRequest" method. By chance, at some point, an error "UsersTooMuchError - The maximum number of users has been exceeded (to create a chat, for example)." was discovered. Should anyone know how to solve this problem?
Читать полностью…https://docs.telethon.dev/en/stable/modules/client.html#telethon.client.telegrambaseclient.TelegramBaseClient
Passing device_model
Changing the IP address requires using a proxy
https://docs.telethon.dev/en/stable/basic/signing-in.html#signing-in-behind-a-proxy
This is the code i had:from telethon import TelegramClient, events, sync, types
import os
# Estos valores de ejemplo no funcionarán. Debes obtener tu propio api_id y
# api_hash desde https://my.telegram.org, en la sección de API Development.
api_id = ...
api_hash = '...'
client = TelegramClient('session_name', api_id, api_hash)
client.start()
to_chat =
from_chat =
@client.on(events.NewMessage(chats=from_chat))
async def fwd(e):
restricted = e.noforwards or e.chat.noforwards
is_web_preview = isinstance(e.media, types.MessageMediaWebPage)
if e.media and not is_web_preview and restricted:
file = await e.download_media()
e.media = await client.upload_file(file)
os.remove(file)
print('Received event', e.stringify())
await client.send_message(to_chat, e.message)
@client.on(events.MessageEdited(chats=from_chat))
async def fwd_edited(e):
restricted = e.noforwards or e.chat.noforwards
is_web_preview = isinstance(e.media, types.MessageMediaWebPage)
if e.media and not is_web_preview and restricted:
file = await e.download_media()
e.media = await client.upload_file(file)
os.remove(file)
e.text = "(Edit)\n" + e.text
print('Received edited event', e.stringify())
await client.send_message(to_chat, e.message)
client.run_until_disconnected()
Hi and welcome to the group. Before asking any questions, please read the rules from the group's description, and don't forget to read the docs. Make sure you are using the latest version with pip3 install -U telethon
, since most problems have already been fixed in newer versions.
telethon.errors.rpcerrorlist.AuthKeyDuplicatedError
how to skip this rpc error and disconnect client?
telethon.errors.rpcerrorlist.FloodWaitError: A wait of 9720 seconds is required (caused by ResolveUsernameRequest)
Читать полностью…New StackOverflow question
Telethon message request sometimes returns empty message's raw_text, text and message attributes
https://stackoverflow.com/q/79268211
In next update of library, please update this class:
class Factorization:
@classmethod
def factorize(cls, pq):
if pq % 2 == 0:
return 2, pq // 2
y = random.randint(1, pq - 1)
c = random.randint(1, pq - 1)
g, r, q = 1, 1, 1
while g == 1:
x = y
y = (pow(y, 2, pq) + c) % pq
for _ in range(r):
y = (pow(y, 2, pq) + c) % pq
k = 0
while k < r and g == 1:
for _ in range(r - k):
y = (y * y + c) % pq
q = (q * abs(x - y)) % pq
g = cls.gcd(q, pq)
k += r
r *= 2
if g == pq:
while True:
y = (y * y + c) % pq
g = cls.gcd(abs(x - y), pq)
if g > 1:
break
p, q = g, pq // g
return (p, q) if p < q else (q, p)
@staticmethod
def gcd(a, b):
while b:
a, b = b, a % b
return a
This is very strange, you can get it through ID, but getting it directly will prompt the bot client not to use it.😂
Читать полностью…The bot client cannot be used
async for message in event.client.iter_messages(entity):
But if you pass in, ids can be used. If I use the bot client, can I only do it by continuously passing the ID?
Hello, I made a program to resend messages from one grupo to another but now the first group has topics. Can someone help me? I did it long time ago and I am lost now. I supose I need topic ids but I dont even know how to get them
Читать полностью…is there any way to change these infos in userbot sessions using code in telethon?
Читать полностью…Telegram client has a bug that doesn't let the admins delete previous profile pictures of a group chat
Is there any function in telethon to delete previous profile pictures of a group/channel?
New StackOverflow question
Telethon - How to trigger a UNIQUE "events.NewMessage" by clicking inline button?
https://stackoverflow.com/q/79259019
ty, I'm waiting for someone to do something, then I'll msg you, I'll do that in like 5-10 min
Читать полностью…