[英]Send photo in telegram bot with python
With this code, I take a screenshot of the screen and save it in memory使用此代码,我截取屏幕截图并将其保存在 memory
I want to send this photo by bot \我想通过机器人发送这张照片 \
import pyscreenshot
def take_pic():
image = pyscreenshot.grab()
return image.show()
take_pic()
and bot code is:机器人代码是:
elif number == "??????":
data = take_pic()
query.edit_message_text(
text=f"{data}",
reply_markup=build_keyboard(number_list),
my lib is:我的库是:
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, bot, message, update
from telegram.ext import ( Updater, CommandHandler, CallbackQueryHandler, CallbackContext, InvalidCallbackData, PicklePersistence,filters,BaseFilter )
pyscreenshot
is an obsolate library and may not work on some OS. pyscreenshot
是一个过时的库,可能无法在某些操作系统上运行。 Please update your post with more details.请更新您的帖子以提供更多详细信息。
Just using the Requests lib you can do it:只需使用 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.