0

With this code, I take a screenshot of the screen and save it in 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 )
ashkan
  • 530
  • 3
  • 11
  • Hi, please include some additional information in your answer. What is it currently doing? Does it send anything? – Jessie Jan 04 '22 at 06:04
  • I'm getting information from the bot, but I need to send a screenshot to the bot right now In other parts, I have no problem sending information, but I have not found the right solution in sending the image yet – ashkan Jan 04 '22 at 06:34

1 Answers1

-1

image.show only returns True or False because the reutrn type of pyscreenshot.grab is PIL.Image not regular imag bytes data. Instead save image in temporary dir and return file path for further instruction. Try this :

img = pyscreenshot.grab()

name = "temp.png"
img.save(name)

bot.send_document(chat_id = chat_id, document = open(name, "rb"))
S.A.H
  • 38
  • 4