【发布时间】:2020-09-01 21:05:00
【问题描述】:
- 我已尝试将 EditBannedRequest 方法用于私人频道, 与客户端一起使用时效果很好,但是,当我使用机器人时 拥有频道管理员权限,我收到此错误 Main.telethon.errors.rpcerrorlist.BotMethodInvalidError:API 机器人用户的访问受到限制。您尝试调用的方法 无法作为机器人执行(由 CheckChatInviteRequest 引起)
- 我处理了 EditBannedRequest 方法直接接收有效 没有执行 get_input_channel 和 get_input_entity 的实体 方法...然后,我打印了为机器人生成的值,然后 与为客户端生成的值进行比较,结果相等。
例如:
在 Telegram 方法中,我修改了 resolve 函数:
async def resolve(self, client, utils):
if isinstance(self.channel, InputChannel) and isinstance(self.user_id, InputUser):
self.channel = self.channel
self.user_id = self.user_id
else:
self.channel = utils.get_input_channel(await client.get_input_entity(self.channel))
self.user_id = utils.get_input_user(await client.get_input_entity(self.user_id))
客户端生成的值:
InputChannel(channel_id=XXXXXX, access_hash=XXXXXX)
机器人发送的值: INVITE_ACCESS = [InputChannel(channel_id=XXXXXXX, access_hash=XXXXXXX)] USER = [InputUser(user_id=XXXXXXX, access_hash=-XXXXXXX)]
功能是这样的:
with TelegramClient(phone, api_id, api_hash).start(bot_token=bot_token) as bot:
result = bot(functions.channels.EditBannedRequest(
channel=INVITE_ACCESS[0],
user_id=USER[0],
banned_rights=types.ChatBannedRights(
until_date=None,
view_messages=True,
send_messages=True
)
))
print(result.stringify())
最后的错误是这样的:
Traceback (most recent call last):
File "banneduser.py", line 41, in <module>
client(EditBannedRequest(
File "/usr/local/lib/python3.8/dist-packages/telethon/sync.py", line 39, in syncified
return loop.run_until_complete(coro)
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/usr/local/lib/python3.8/dist-packages/telethon/client/users.py", line 30, in _call_
return await self._call(self._sender, request, ordered=ordered)
File "/usr/local/lib/python3.8/dist-packages/telethon/client/users.py", line 77, in _call
result = await future
telethon.errors.rpcerrorlist.ChannelInvalidError: Invalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited (caused by EditBannedRequest)
有什么方法可以让机器人在私人频道中毫无问题地运行 EditBannedRequest 方法?
【问题讨论】:
标签: telegram telegram-bot telethon