我只是在实现一个简单的机器人,它应该将一些照片和视频发送到我的 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/