tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

GetSupergroup return error "400 Invalid supergroup identifier" #2842

Closed Pumpkin-A closed 6 months ago

Pumpkin-A commented 6 months ago

I want to get full information about the supergroup, but when I try to use the methods "GetSupergroup" or "GetSupergroupFullInfo" I get an error "400 Invalid supergroup identifier". The user is subscribed to this chat, so that's not the problem

func (ss SalesService) getSupergroupInfo(ctx context.Context, user BotClient) error {
    req := client.GetChatsRequest{
        ChatList: &client.ChatListMain{}, 
        Limit:    100,                    
    }

    chats, err := user.botTg.GetChats(&req)
    if err != nil {
        fmt.Printf("GetChatHistory: GetBotUsersChats: %v", err)
    }

    fmt.Println(chats.TotalCount)
    for _, chatId := range chats.ChatIds {
        chat, err := user.botTg.GetChat(&client.GetChatRequest{ChatId: chatId})
        if err != nil {
            return err
        }
            if chat.Type.ChatTypeType() == client.TypeChatTypeSupergroup {
                supergroup, err := user.botTg.GetSupergroup(&client.GetSupergroupRequest{SupergroupId: chatId})
                if err != nil {
                    return err
                }
                fmt.Println(supergroup.MemberCount)

        }
    }
    return nil
}
Pumpkin-A commented 6 months ago

I couldn't figure it out for a long time, but it worked out!

supergroupId := chat.Type.(*client.ChatTypeSupergroup).SupergroupId
            supergroup, err := user.botTg.GetSupergroup(&client.GetSupergroupRequest{SupergroupId: supergroupId})