Skip to content

Instantly share code, notes, and snippets.

@Looons404
Created June 27, 2025 10:36
Show Gist options
  • Save Looons404/31dd0e3db8c93c393206ec14146b40b7 to your computer and use it in GitHub Desktop.
Save Looons404/31dd0e3db8c93c393206ec14146b40b7 to your computer and use it in GitHub Desktop.
I... I don't have a description for this, but it's maybe useful for someone ?
import requests
from PIL import ImageGrab
import io
import time
def capture_screenshot():
screenshot = ImageGrab.grab()
return screenshot
def send_to_discord(webhook_url, screenshot):
with io.BytesIO() as image_binary:
screenshot.save(image_binary, format="PNG")
image_binary.seek(0)
files = {
"file": ("screenshot.png", image_binary, "image/png")
}
response = requests.post(webhook_url, files=files)
if response.status_code == 204:
print("Screenshot sent successfully!")
else:
print(f"Error sending screenshot: {response.status_code}, {response.text}")
if __name__ == "__main__":
DISCORD_WEBHOOK_URL = "" # Add your Discord webhook URL here
if not DISCORD_WEBHOOK_URL:
print("Please configure the Discord webhook URL before continuing.")
exit(1)
print("Starting screenshot capture every 5 seconds. Press Ctrl+C to stop.")
screenshot_count = 0
try:
while True:
print("Capturing screenshot...")
screenshot = capture_screenshot()
print("Sending to Discord webhook...")
send_to_discord(DISCORD_WEBHOOK_URL, screenshot)
screenshot_count += 1
print(f"Total screenshots taken: {screenshot_count}")
time.sleep(5)
except KeyboardInterrupt:
print("Script stopped.")
print(f"Final number of screenshots taken: {screenshot_count}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment