D
D
d3Ka2021-05-12 21:33:35
Python
d3Ka, 2021-05-12 21:33:35

How to send screenshot PyTelegramBotApi?

This must be done without interaction with the bot, i.e. a screen bot sends it and the screen is deleted from the PC.
I suggested this code but it doesn't work.

im=ImageGrab.grab(bbox=(0,0,1920,1080))
im.save('im.png')
sleep(2)
def smt(message):
    if im:
        bot.send_photo(message.chat.id, 'im')
sleep(2)
path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'im.png')
os.remove(path)

Screenshots via Pyscreenshot, all modules are installed, if it is easier, then it is possible on other modules.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jerwright, 2021-05-13
@d3Ka

Try adding this code before sending the message:

with open('путь к файлу', "rb") as file:
                data = file.read()

And already in bot.send_message()as a photo to send data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question