簡體   English   中英

在 python 中使用遠程機器人發送圖片

[英]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()

我無法從機器人發送屏幕截圖,顯示此錯誤:

init .py:515 MainThread) 錯誤 - TeleBot:“對 Telegram API 的請求不成功。錯誤代碼:400。描述:錯誤請求:未找到聊天”

您應該使用“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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM