Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中如何在电报发送消息bot中使用解析模式_Python_Telegram Bot_Telethon - Fatal编程技术网

Python中如何在电报发送消息bot中使用解析模式

Python中如何在电报发送消息bot中使用解析模式,python,telegram-bot,telethon,Python,Telegram Bot,Telethon,我对制造机器人还很陌生,所以我有几个问题想问: 我正在使用机器人发送消息 def send_message(chat_id, msg): url = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={msg}" requests.get(url) send_message(chat_id,msg) 通过这个,我可以发送消息,我想通过使用parse_模式

我对制造机器人还很陌生,所以我有几个问题想问:

  • 我正在使用机器人发送消息

     def send_message(chat_id, msg):
     url = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={msg}"
     requests.get(url)
     send_message(chat_id,msg)
    
  • 通过这个,我可以发送消息,我想通过使用parse_模式来美化结果,但我不知道在url中放在哪里才能使它工作

  • 我可以选择使用电视马拉松。我可以使用它通过用户名和组邀请链接向个人和组发送消息,但当我尝试通过以下方式向频道发送消息时:

    client.send_message(entity='my channel name',message=message)

  • 当我尝试运行它时,它无法找到与“测试通道”对应的任何实体

    我也尝试

    destination_channel_username='test_ali3'
    entity=client.get_entity(destination_channel_username)
    client.send_message(entity=entity,message="Hi")
    
    但它需要我的通道访问\u散列,如何获得它,或者是否有任何其他方式将消息发送到通道

  • 我知道Telegram bot API具有sendMessage或bot.sendMessage之类的功能,也可以执行此任务,但不知何故,我无法调用它,我应该安装和/或导入哪些软件包
  • 非常感谢

  • 这应该可以做到:
  • TBH我对telethon不太熟悉,但该库主要用于所谓的用户机器人。这意味着它使用了Telegram应用程序也使用的API,因此,它通常比普通的bot API更复杂

  • 要在Python中使用Bot API,我可以推荐包
    Python电报Bot
    ,请参阅。免责声明:我目前是该软件包的维护者。还有其他用于bot api的python包,请参见


  • >但该库主要用于所谓的用户机器人。事实并非如此,机器人得到了很好的支持,开销更少(您直接与电报通话),限制也更少。
    def send_message(chat_id, msg, parse_mode):
        url = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={msg}&parse_mode={parse_mode}"
        requests.get(url)