使用 tdlib 和 gogram 找不到频道

问题描述 投票:0回答:1

我正在使用 github.com/amarnathcjd/gogram/telegram 来获取频道消息,我已经安装了 tdlib 版本并且正在使用以下代码:

func main() {
    client, err := telegram.NewClient(telegram.ClientConfig{
        AppID: appID, AppHash: appHash,
    })
    if err != nil {
        fmt.Println(err)
        return
    }

    client.Login(phone)

    tgchannel, err := client.GetChannel(channelIDint)
    if err != nil {
        fmt.Println(err)
        return
    }

    client.Idle() 
}

登录没问题。但是当我尝试获取频道时,我收到此错误消息: 没有 ID 为 -10020055**** 的频道或缓存中缺失

我之前尝试过添加加入,以防万一:

    err = client.JoinChannel(channelIDint)
    if err != nil {
        fmt.Println(err)
        return
    }

但我收到类似的错误消息: 没有 id 为 112094*** 的对等点或缓存中缺少该对等点 这个id好像省略了频道id的前三个数字和减号(-100),不知道为什么。

我缺少什么?

go telegram
1个回答
0
投票

在 Telegram 中,通道 ID 通常以 -100xxxxxxxxxx 的格式表示,其中 xxxxxxxxxx 是实际的通道 ID。然而,基于这个问题,gogram 库似乎希望通道 ID 以整数形式提供,不带 -100 前缀。

我不知道你从哪里得到的channelIDint,但像这样的东西应该可以工作:

func main() {
    client, err := telegram.NewClient(telegram.ClientConfig{
        AppID: appID, AppHash: appHash,
    })
    if err != nil {
        fmt.Println(err)
        return
    }

    client.Login(phone)

    // remove the "-100" prefix from the channel ID
    channelIDint := 2005512345 // your actual channel ID without the "-100" prefix

    tgchannel, err := client.GetChannelFull(channelIDint)
    if err != nil {
        fmt.Println(err)
        return
    }

    // print the channel information
    fmt.Println(tgchannel.Title)
    fmt.Println(tgchannel.Description)

    client.Idle()
}
© www.soinside.com 2019 - 2024. All rights reserved.