I want to send a screenshot over a discord webhook. I am using the dhooks module for this. To send a file, I need a "file-like object" so I want to get a file-like object without having the need to store the screenshot as a file. Any idea how to do this?
Asked
Active
Viewed 442 times
1 Answers
2
I just added an example in the documentation:
import mss
import mss.tools
with mss.mss() as sct:
# The monitor or screen part to capture
monitor = sct.monitors[1] # or a region
# Grab the data
sct_img = sct.grab(monitor)
# Generate the PNG
png = mss.tools.to_png(sct_img.rgb, sct_img.size)

Tiger-222
- 6,677
- 3
- 47
- 60
-
That worked. Thank you! – Mark Mikealson Dec 17 '21 at 19:51
-
Though I have one more question, if we want to capture the screen of the first monitor, why don't we do `sct.monitors[0]` instead of `sct.monitors[1]`? – Mark Mikealson Dec 17 '21 at 20:54
-
1Here is the [explanation](https://python-mss.readthedocs.io/api.html#mss.tools.mss.base.MSSBase.monitors) ;) – Tiger-222 Dec 18 '21 at 08:07
-
Understood it, thanks so much for all the help :) – Mark Mikealson Dec 19 '21 at 17:05