python - 如何在电报机器人上发送照片

标签 python telegram-bot telepot

我只是在实现一个简单的机器人,它应该将一些照片和视频发送到我的 chat_id。 好吧,我正在使用 python,这是脚本

import sys
import time
import random
import datetime
import telepot

def handle(msg):
    chat_id = msg['chat']['id']
    command = msg['text']

    print 'Got command: %s' % command

    if command == 'command1':
        bot.sendMessage(chat_id, *******)
    elif command == 'command2':
        bot.sendMessage(chat_id, ******)
    elif command == 'photo':
        bot.sendPhoto(...)

bot = telepot.Bot('*** INSERT TOKEN ***')
bot.message_loop(handle)
print 'I am listening ...'

while 1:
    time.sleep(10)

bot.sendphoto 行中,我将插入图像的路径和 chat_id,但没有任何反应。

我哪里错了?

谢谢

最佳答案

如果你有本 map 片路径:

bot.send_photo(chat_id, photo=open('path', 'rb'))

如果您有来自互联网的图片网址:

bot.send_photo(chat_id, 'your URl')

关于python - 如何在电报机器人上发送照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36778321/

相关文章:

flask - 连接已建立时发生连接错误

Python:初始化大量类成员的便捷方法

Python 3 不会从 Git Bash 命令行运行

telegram - 通过 Telegram 聊天 ID 可以做什么?

python - 有没有办法让 Telepot bot 读取来自其他 bot 的消息?

python - 如何在 bot.sendMessage() 中发送超链接

python - Emacs不同框架中的不同python venv

python - Pandas :按特定日期分组

regex - Telegram Bot API 4.5 MarkdownV2 上的转义字符给超链接带来麻烦

excel - Excel VBA 使用 Telegram bot api 发送图像