Telethon 不允许机器人加入频道(您尝试调用的方法无法作为机器人执行(由 JoinChannelRequest 引起)

Telethon doesn't allow a bot to join a channel (The method you tried to invoke cannot be executed as a bot (caused by JoinChannelRequest)

我是 Telethon 的新手,我仍然有疑问。

我的任务似乎很简单:我想创建一个机器人来 从频道中抓取 一些信息,但我在第一步中遇到了困难:将机器人加入频道。

为了确保我做得很好,我在 telethon.dev 页面中寻找并找到这段代码,我正在尝试:

from telethon.sync import TelegramClient
from telethon import functions, types

api_id = XXXXXXXXXXXX
api_hash = 'XXXXXXXXXXXXXXXXXXXXXX'
token= 'XXXXXXXXXXXXXXXXXXXXXX'

with TelegramClient('anon', api_id, api_hash) as client:
    result = client(functions.channels.JoinChannelRequest(
        channel='publicchanel'
    ))
    print(result.stringify())

我也尝试以机器人身份登录,使用(当然,更改它需要的内容 changed/added):

bot = TelegramClient('bot', api_id, api_hash).start(bot_token=token)

但是我也遇到同样的错误:

telethon.errors.rpcerrorlist.BotMethodInvalidError: The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by JoinChannelRequest)

我做错了什么?

PD:如果重要的话:我正在使用 Debian10 作为 OS

这不是 Telethon 限制,而是 Telegram 限制。机器人无法自行加入群组或频道,需要由用户添加。

机器人无法加入,请在 Graph Messenger 中使用机器人登录并查看其工作方式。 您应该将机器人添加到频道并授予他管理员权限。 如果你仔细查看文档,你会发现这个加入频道的方法只适用于用户。