【问题标题】:send picture with telebot in python在 python 中使用 Telebot 发送图片
【发布时间】:2021-01-24 17:20:46
【问题描述】:
import telebot
import urllib.request
import pyautogui
bot = telebot.TeleBot("TOKEN", parse_mode=None)

@bot.message_handler('start')
def send_welcome(message):
    bot.reply_to(message, "Hi Wellcome To Server Manager Bot")
    enter code here
@bot.message_handler('getip')
def send_targetip(message):
    target_ip = urllib.request.urlopen("http://ip.42.pl/short")
    ip = target_ip.read()
    bot.reply_to(message,ip)
@bot.message_handler('screen')
def capture_screen(send_photo):
    screenimage = pyautogui.screenshot("screen.png")
    screenimage.save("C:\\Users\\HO3IN\\Desktop\\screen.png")
    photo = open("C:\\Users\\user\\Desktop\\screen.png",'rb')
    bot.send_photo(capture_screen,photo)
    photo.close()
bot.polling()

我无法从机器人发送屏幕截图,显示此错误:

init.py:515 MainThread) 错误 - TeleBot:“对 Telegram API 的请求不成功。错误代码:400。描述:错误 请求:未找到聊天”

【问题讨论】:

    标签: python telegram-bot


    【解决方案1】:

    您应该使用“message.chat.id”而不是“message”。

    bot.reply_to(message.chat.id,"Hi")
    bot.reply_to(message.chat.id,ip)
    bot.send_photo(send_photo.chat.id,photo)
    

    【讨论】:

      猜你喜欢
      • 2022-12-23
      • 2012-02-18
      • 2020-07-25
      • 2015-11-26
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 2020-08-10
      相关资源
      最近更新 更多