【问题标题】:value error while trying to join a channel using telethon尝试使用 Telethon 加入频道时出现值错误
【发布时间】:2021-01-02 11:31:41
【问题描述】:

我有一个代码需要加入给定频道,但出现以下错误

telethon.errors.rpcerrorlist.ChannelInvalidError:无效的频道对象。确保传递正确的类型,例如确保请求是为频道设计的,或者寻找更适合的不同类型(由 JoinChannelRequest 引起)

我的代码:

group_input = InputChannel(group.id, group.access_hash)
client(JoinChannelRequest(group_input))

我在这里使用 inputChannel,因为我查看了 joinChannelRequest,它要求输入“TypeInputChannel” 它是 [InputChannelEmpty,InputChannel,InputChannelFromMessage] 的并集

我尝试过的另一件事:

1-

client(JoinChannelRequest(group.id))

2-

client(JoinChannelRequest(group))

3-

group_input = InputPeerChannel(group.id, group.access_hash)
client(JoinChannelRequest(group_input))

【问题讨论】:

  • 您有想要加入的频道的链接或用户名吗?
  • 是的,我有链接
  • 但在某些情况下我没有链接或用户名,我也需要处理它,我可能有 id

标签: python python-3.x telegram telethon


【解决方案1】:

您可以做的最简单的方法是检索公共频道的用户名
假设频道的用户名是@The_Channel
获取实体
entity = client.get_entity("t.me/The_Channel") #omit @
然后调用这个函数
client(JoinChannelRequest(entity))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-15
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    相关资源
    最近更新 更多