0% found this document useful (0 votes)
28 views5 pages

Discord Screenshot Automation Script

macro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

Discord Screenshot Automation Script

macro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

; macro#1 - AutoHotkey Image Monitor Script dengan Discord Screenshot

; F7 = Start/Stop Script (normal monitoring)


; F8 = Start/Stop Script (run [Link] first)
; F5 = Check Image [Link]
; F9 = Kill/Force Stop [Link]
; Esc = Exit Script

#NoEnv
#SingleInstance Force
#Persistent
SendMode Input
SetWorkingDir %A_ScriptDir%

; --- Discord Bot Settings ---


botToken := "MTQxOTYwNjY1MDQ4NjI2MzgyOQ.G-XwBa.cxPENemrzAMJqpmp4XS-UdTV-
aV5mflCU49HMQ"
channelID := "1270571630388576421"
screenshotDir := A_ScriptDir . "\screenshots"

; Buat folder screenshots jika belum ada


FileCreateDir, %screenshotDir%

; Variable untuk kontrol script


ScriptRunning := false

; Hotkey F7 untuk memulai/menghentikan script


F7::
if (ScriptRunning) {
ScriptRunning := false
ToolTip, Script STOPPED, 10, 10
SetTimer, RemoveToolTip, 2000
} else {
ScriptRunning := true
ToolTip, Script STARTED, 10, 10
SetTimer, RemoveToolTip, 2000
Gosub, MainScript
}
return

; Hotkey F8 untuk langsung jalankan [Link] lalu monitoring


F8::
if (ScriptRunning) {
ScriptRunning := false
ToolTip, Script STOPPED, 10, 10
SetTimer, RemoveToolTip, 2000
} else {
ScriptRunning := true
ToolTip, Script STARTED - Running [Link] first..., 10, 10
SetTimer, RemoveToolTip, 2000
; Langsung jalankan [Link] dulu
RunWait, [Link]
ToolTip, [Link] finished! Starting monitoring..., 10, 10
SetTimer, RemoveToolTip, 2000
Gosub, MainScript
}
return

; Hotkey F9 untuk kill/force stop [Link]


F9::
Process, Close, [Link]
if (ErrorLevel = 0) {
ToolTip, [Link] KILLED successfully!, 10, 70
} else {
ToolTip, [Link] not running or failed to kill, 10, 70
}
SetTimer, RemoveToolTip, 3000
return

F5::
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *50 [Link]
if (ErrorLevel = 0) {
ToolTip, IMAGE FOUND at X:%FoundX% Y:%FoundY%, 10, 30
} else if (ErrorLevel = 1) {
ToolTip, IMAGE NOT FOUND, 10, 30
} else {
ToolTip, ERROR: [Link] file not found in script directory, 10, 30
}
SetTimer, RemoveToolTip, 3000
return

; Main Script Loop


MainScript:
Loop {
if (!ScriptRunning)
break

; Check apakah [Link] ada


ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *50 [Link]
if (ErrorLevel = 0) {
; Jika [Link] ditemukan, jalankan [Link]
ToolTip, Script running - [Link] found! Starting [Link]..., 10, 50
; Jalankan [Link] dan tunggu sampai selesai
RunWait, [Link]
; Setelah [Link] selesai, jalankan [Link]
ToolTip, Script running - [Link] finished! Starting [Link]..., 10, 50
RunWait, [Link]
; Setelah [Link] selesai, lanjut loop lagi
ToolTip, Script running - [Link] finished! Back to monitoring..., 10, 50
} else {
; Check apakah [Link] ada
ImageSearch, RetryX, RetryY, 0, 0, A_ScreenWidth, A_ScreenHeight, *50
[Link]
if (ErrorLevel = 0) {
; Jika [Link] ditemukan, screenshot dulu dan kirim ke Discord
ToolTip, Script running - [Link] found! Taking screenshot..., 10, 50
SetTimer, RemoveToolTip, 2000

; SCREENSHOT DAN KIRIM KE DISCORD DULU


TakeScreenshotAndSend()

; BARU jalankan [Link] setelah screenshot


ToolTip, Script running - Screenshot sent! Starting [Link]..., 10,
50
RunWait, [Link]

; Setelah [Link] selesai, jalankan [Link]


ToolTip, Script running - [Link] finished! Starting [Link]...,
10, 50
RunWait, [Link]

; Setelah [Link] selesai, lanjut loop lagi


ToolTip, Script running - [Link] finished! Back to monitoring...,
10, 50
} else {
; Jika kedua image tidak ditemukan
ToolTip, Script running - Waiting for [Link] or [Link]..., 10, 50
}
}

; Delay untuk mencegah CPU usage tinggi


Sleep, 500
; Update tooltip setiap loop
SetTimer, RemoveToolTip, 1000
}
return

; --------- SCREENSHOT & DISCORD FUNCTIONS ---------


TakeScreenshotAndSend() {
global screenshotDir, botToken, channelID

; Ambil screenshot window aktif


WinGet, activeWin, ID, A
if (!activeWin) {
; Jika tidak ada window aktif, screenshot seluruh layar
TakeFullScreenshot()
return
}

; Dapatkan posisi window aktif


WinGetPos, rX, rY, rW, rH, ahk_id %activeWin%

; Generate nama file unik


FormatTime, timeStamp, , yyyy-MM-dd_HH-mm-ss
screenshotFile := screenshotDir . "\retry_screenshot_" . timeStamp . ".png"

; Ambil screenshot area window


if (rX != "" and rY != "" and rW != "" and rH != "") {
TakeAreaScreenshot(rX, rY, rW, rH, screenshotFile)
} else {
; Fallback ke fullscreen
TakeFullScreenshot(screenshotFile)
}

; Kirim ke Discord jika file berhasil dibuat


if FileExist(screenshotFile) {
SendToDiscord(screenshotFile)
}
}

TakeAreaScreenshot(x, y, w, h, filePath) {
; Screenshot area menggunakan PowerShell
psCmd := "Add-Type -AssemblyName [Link],[Link]; "
psCmd .= "$bounds = New-Object [Link](" . x . "," . y . "," .
w . "," . h . "); "
psCmd .= "$bmp = New-Object [Link](" . w . "," . h . "); "
psCmd .= "$graphics = [[Link]]::FromImage($bmp); "
psCmd .= "$[Link]($[Link],
[[Link]]::Empty, $[Link]); "
psCmd .= "$[Link]('" . filePath . "',
[[Link]]::Png); "
psCmd .= "$[Link](); $[Link]();"

RunWait, [Link] -Command "%psCmd%", , Hide


}

TakeFullScreenshot(filePath := "") {
global screenshotDir

if (filePath = "") {
FormatTime, timeStamp, , yyyy-MM-dd_HH-mm-ss
filePath := screenshotDir . "\retry_fullscreen_" . timeStamp . ".png"
}

; Screenshot seluruh layar


psCmd := "Add-Type -AssemblyName [Link],[Link]; "
psCmd .= "$bounds = [[Link]]::[Link]; "
psCmd .= "$bmp = New-Object [Link]($[Link],
$[Link]); "
psCmd .= "$graphics = [[Link]]::FromImage($bmp); "
psCmd .= "$[Link]($[Link],
[[Link]]::Empty, $[Link]); "
psCmd .= "$[Link]('" . filePath . "',
[[Link]]::Png); "
psCmd .= "$[Link](); $[Link]();"

RunWait, [Link] -Command "%psCmd%", , Hide

; Kirim ke Discord
if FileExist(filePath) {
SendToDiscord(filePath)
}
}

SendToDiscord(filePath) {
global botToken, channelID

if (botToken = "YOUR_BOT_TOKEN_HERE") {
return
}

; Baca ukuran file


FileGetSize, fileSize, %filePath%
if (fileSize > 8388608) { ; 8MB limit Discord
return
}

; Buat curl command untuk upload ke Discord


curlCmd := "curl -X POST """ . "[Link] .
channelID . "/messages"" "
curlCmd .= "-H ""Authorization: Bot " . botToken . """ "
curlCmd .= "-F ""file=@" . filePath . """ "
curlCmd .= "-F ""content=🔄 RETRY DETECTED - Screenshot sent from AutoHotkey
Bot"""

; Jalankan curl command


RunWait, %curlCmd%, , Hide
; Hapus file setelah upload
Sleep, 1000
FileDelete, %filePath%
}

; Function untuk menghilangkan tooltip


RemoveToolTip:
ToolTip
return

; Hotkey Esc untuk keluar dari script


Esc::
ScriptRunning := false
ToolTip, Script EXITED, 10, 10
SetTimer, RemoveToolTip, 2000
Sleep, 2000
ExitApp
return

; Info script saat startup


^j:: ; Ctrl+J untuk help
MsgBox, 64, AutoHotkey Image Checker + Discord Screenshot Help,
(
Hotkeys:
F7 = Start/Stop Script (normal monitoring)
F8 = Start/Stop Script (run [Link] first)
F5 = Check [Link] image
F9 = Kill/Force Stop [Link]
Esc = Exit script completely
Ctrl+J = Show this help

Features:
- Auto screenshot when [Link] detected
- Send screenshot to Discord before running [Link]
- Normal monitoring for [Link]

Setup:
1. Replace YOUR_BOT_TOKEN_HERE with your Discord bot token
2. Place [Link] and [Link] in script folder
3. Ensure curl is installed for Discord upload

Note: Screenshots saved to screenshots/ folder


)
return

You might also like