如何解决获取频道/聊天实体
我希望有人可以将我的机器人添加到他的频道。为此,我想将频道的 webhook (chat.id) 保存在数据库中。
我的代码:
async with bot.conversation(chat.id) as conv:
await conv.send_message("Which channel you want add? (invite link of the channel):")
resp = await conv.get_response()
hookName = resp.message
hook = await bot.get_entity(hookName)
print(hook)
print(hook.chat_id)
print(hook.user_id)
当我使用邀请链接时,我在 get_entity 行收到此错误:
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 CheckChatInviteRequest)
当我使用频道名称时出现这个错误:
ValueError: No user has "channelname" as username
我想知道为什么当我对频道名称进行硬编码而不是作为响应时它会起作用...
如果用户只需输入聊天名称或频道名称或邀请链接,我就可以从中获取 ID,那就太好了。
有没有办法做到这一点?
谢谢:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。