python - 获取频道/聊天实体
问题描述
我希望有人可以将我的机器人添加到他的频道。为此,我想将频道的 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,那就太好了。
有没有办法做到这一点?
谢谢 :)
解决方案
推荐阅读
- javascript - JavaScript Fetch:有编码问题的字符
- javascript - 引导选择不会在 changed.bs.select 上返回 clickedIndex
- angularjs - angular7 中 angular.copy 的替代方法是什么?
- hadoop - HIVE - 创建字符串本身包含逗号的外部表
- sbt - sbt throws 提供的 AspectJ 编织外部 jar 文件无法确定缺少类型的超类
- java - 按下按钮小部件和片段问题
- python - 熊猫,从 read_csv 合并日期和时间列
- tensorflow - 将 Keras 模型转换为 Layers API 格式模型以与 tensorflow.js 一起使用时出现问题
- angular - 在 Angular 测试中监视对象属性
- c# - 如何可视化指标应用洞察?