并非所有组都在 Telethon 中可见

CoD*_*ign 2 python telegram telethon

我使用chat.megagroup==true 它没有显示所有频道(在m==1),而且它也有问题,例如有时显示 A 组和 B 组,有时显示 A 或 B,有时显示 C 组,不知道为什么甚至无需更改代码中的任何内容即可发生。

该脚本总体工作正常,但唯一的问题是我有时没有需要使用的组。

result = client(GetDialogsRequest(
             offset_date=last_date,
             offset_id=0,
             offset_peer=InputPeerEmpty(),
             limit=chunk_size,
             hash = 0))

chats.extend(result.chats)
dialogs = client.get_dialogs()

m = input("1: For only permitted groups \n2: For all groups\n")
if m=='1':
    for chat in chats:
        try:
            if chat.megagroup == True:
                groups.append(chat)
        except:
            continue
elif m=='2':
    for i in dialogs:
        try:
            i.entity.status
        except:
            groups.append(i)
            continue
Run Code Online (Sandbox Code Playgroud)

在 中m==2,显示了所有组。你能指导我做错了什么还是别的什么?

Lon*_*ami 5

GetDialogsRequest是一个原始请求,Telegram 的最大限制为 100。您不应该使用它,并且您应该始终更喜欢使用client.get_dialogs(). 您可以检查它是否是一个带有 的组dialog.is_group,以及一个带有 的频道dialog.is_channel。因此,对于大型集团来说:

if dialog.is_group and dialog.is_channel:
    # it's a megagroup (= supergroup)
Run Code Online (Sandbox Code Playgroud)

这些属性可以在https://docs.telethon.dev/en/latest/modules/custom.html#telethon.tl.custom.dialog.Dialog的文档中找到。