telethonchat | Unsorted

Telegram-канал telethonchat - Telethon Chat

6097

Official Telethon's chat! Rules: • Speak English • Stay on topic (questions about Telethon) • Be respectful • Don't ask to ask • Spam-related uses lead to ban • Read https://docs.telethon.dev before asking things here Read more about us @TelethonUpdates

Subscribe to a channel

Telethon Chat

from telethon import TelegramClient
bot = TelegramClient(...)


After a while (> 1 day) it gets stuck and the bot does not respond to commands.
Can it be that my telegram bot becomes unresponsive due to the connection being dropped or timing out if left idle for too long?

Читать полностью…

Telethon Chat

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)





I test that the bot client must retrieve messages by ids. Is there a faster way than mine?

Читать полностью…

Telethon Chat

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

Читать полностью…

Telethon Chat

may I know in what context this will be faster?

Читать полностью…

Telethon Chat

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?

Читать полностью…

Telethon Chat

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

Читать полностью…

Telethon Chat

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()

Читать полностью…

Telethon Chat

why id getting AttributeError in File object?
i send a photo with URL to Telegram

Читать полностью…

Telethon Chat

some unofficial telegram app show your contact has saved your number or not

Читать полностью…

Telethon Chat

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 Chat

telethon.errors.rpcerrorlist.AuthKeyDuplicatedError

how to skip this rpc error and disconnect client?

Читать полностью…

Telethon Chat

How can I handle the updates that come when removing a user from the channel?

Читать полностью…

Telethon Chat

not with the builtin session types. you'll need your own

Читать полностью…

Telethon Chat

ChatAction does not work for this

Читать полностью…

Telethon Chat

Alright I would be waiting tho

Читать полностью…

Telethon Chat

telethon.errors.rpcerrorlist.FloodWaitError: A wait of 9720 seconds is required (caused by ResolveUsernameRequest)

Читать полностью…

Telethon Chat

Thank you! Are you a blackmamba?

Читать полностью…

Telethon Chat

New StackOverflow question
Telethon message request sometimes returns empty message's raw_text, text and message attributes

https://stackoverflow.com/q/79268211

Читать полностью…

Telethon Chat

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

It has been tested and is 10* faster than previous version

Читать полностью…

Telethon Chat

This is very strange, you can get it through ID, but getting it directly will prompt the bot client not to use it.😂

Читать полностью…

Telethon Chat

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?

Читать полностью…

Telethon Chat

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

Читать полностью…

Telethon Chat

If your number is hidden, they can't see it like no one else.

Читать полностью…

Telethon Chat

is there any way to change these infos in userbot sessions using code in telethon?

Читать полностью…

Telethon Chat

try:
#...
except:
client.disconnect()

Читать полностью…

Telethon Chat

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?

Читать полностью…

Telethon Chat

hi lonami
how are you
A long time ago about you

Читать полностью…

Telethon Chat

Hello, is it possible to create multiple sessions in one file?

Читать полностью…

Telethon Chat

New StackOverflow question
Telethon - How to trigger a UNIQUE "events.NewMessage" by clicking inline button?

https://stackoverflow.com/q/79259019

Читать полностью…

Telethon Chat

ty, I'm waiting for someone to do something, then I'll msg you, I'll do that in like 5-10 min

Читать полностью…
Subscribe to a channel