[英]Send photo in telegram bot with python
使用此代碼,我截取屏幕截圖並將其保存在 memory
我想通過機器人發送這張照片 \
import pyscreenshot
def take_pic():
image = pyscreenshot.grab()
return image.show()
take_pic()
機器人代碼是:
elif number == "??????":
data = take_pic()
query.edit_message_text(
text=f"{data}",
reply_markup=build_keyboard(number_list),
我的庫是:
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, bot, message, update
from telegram.ext import ( Updater, CommandHandler, CallbackQueryHandler, CallbackContext, InvalidCallbackData, PicklePersistence,filters,BaseFilter )
pyscreenshot
是一個過時的庫,可能無法在某些操作系統上運行。 請更新您的帖子以提供更多詳細信息。
只需使用 Requests lib,您就可以做到:
def send_photo(chat_id, file_opened):
method = "sendPhoto"
params = {'chat_id': chat_id}
files = {'photo': file_opened}
resp = requests.post(api_url + method, params, files=files)
return resp
send_photo(chat_id, open(file_path, 'rb'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.