Answer the question
In order to leave comments, you need to log in
How to send a screenshot of a computer screen to VK through a bot written in Python?
I want to make a VK bot that can take a screenshot of the screen and send it to me on VK.
I found a way to take a screenshot of the screen. But I don't know how to send this image.
If you have any ideas on how to send a screenshot, please share your method.
import vk_api, subprocess, pyautogui as pg
pg.screenshot("screenshotacran.jpg")
Answer the question
In order to leave comments, you need to log in
Here, try it.
import mss
import vk_api
import requests
from random import randint
FILE_NAME = "1.png"
vk_session = vk_api.VkApi(token = 'ТУТ_ТОКЕН') # Можно получить вбив в Google
vk = vk_session.get_api()
with mss.mss() as sct:
sct.shot(output = FILE_NAME)
url = vk.photos.getMessagesUploadServer()['upload_url']
photo = requests.post(url, files = {'photo': open(FILE_NAME, 'rb')}).json()
save_ = vk.photos.saveMessagesPhoto(server = photo['server'], photo = photo['photo'], hash = photo['hash'])[0]
vk.messages.send(
user_id = 0, # ТУТ ID ЮЗЕРА
random_id = randint(-2147483648, 2147483647),
attachment = "photo%s_%s" % (save_['owner_id'], save_['id'])
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question