Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

telegram bot - send picture with telebot in python

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()

I can't send screenshot from bot, show me this error:

init.py:515 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: chat not found"

question from:https://stackoverflow.com/questions/65873682/send-picture-with-telebot-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should use "message.chat.id" instead of "message".

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...