Skip to content

Commit 104ea77

Browse files
committed
🤖 Added Discord Webhook integration
If configured, server can now send start/stop messages to a Discord channel. If not configured, the script runs the same as before.
1 parent 09d620c commit 104ea77

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

START.bat

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@echo off
22
title Checking dependencies...
3-
set scriptVersion=v1.2.2
4-
set currentConfigVersion=v1.2.2
3+
set scriptVersion=v1.3.0
4+
set currentConfigVersion=v1.3.0
55

66
REM Set restart counter variables
77
set "restartCount=0"
@@ -117,20 +117,37 @@ if "%autoRestart%"=="true" (
117117

118118
:runRestart
119119
title %Title% ^| Restarted: %restartCount% times
120+
REM Check if webhook URL is set and send start message
121+
if not "%webhookURL%"=="" (
122+
curl -H "Content-Type: application/json" -X POST -d "{\"content\":\"%webhookMessageStart%\"}" %webhookURL%
123+
)
124+
REM Start the server
120125
java %RAM% %args% -jar %serverName% %GUI%
121126
echo.
122127
echo.
123128
set /A restartCount+=1
124129
set "restartTime=%TIME%, %DATE%"
125130
echo Server has closed or crashed...restarting now...
126131
echo Server has restarted %restartCount% times. Last restart: %restartTime%
132+
REM Check if webhook URL is set and send stop message
133+
if not "%webhookURL%"=="" (
134+
curl -H "Content-Type: application/json" -X POST -d "{\"content\":\"%webhookMessageStop%\"}" %webhookURL%
135+
)
127136
goto scriptUpdater
128137

129138
:runNoRestart
130139
title %Title%
140+
REM Check if webhook URL is set and send start message
141+
if not "%webhookURL%"=="" (
142+
curl -H "Content-Type: application/json" -X POST -d "{\"content\":\"%webhookMessageStart%\"}" %webhookURL%
143+
)
131144
java %RAM% %args% -jar %serverName% %GUI%
132145
echo.
133146
echo.
147+
REM Check if webhook URL is set and send stop message
148+
if not "%webhookURL%"=="" (
149+
curl -H "Content-Type: application/json" -X POST -d "{\"content\":\"%webhookMessageStop%\"}" %webhookURL%
150+
)
134151
echo Server has closed or crashed.
135152
CHOICE /N /C YN /M "Do you want to restart the server? (Y/N): "
136153
if %errorlevel%==1 goto scriptUpdater
@@ -212,6 +229,15 @@ echo Enable server GUI?
212229
CHOICE /N /T 5 /D N /C:YN /M "GUI (Y/N): "
213230
if %errorlevel%==1 set GUI=true
214231
if %errorlevel%==2 set GUI=false
232+
cls
233+
echo Enable Discord webhooks?
234+
echo This will post stop/start notifications.
235+
CHOICE /N /C YN /M "Proceed with Discord webhook setup? (Y/N)"
236+
if %errorlevel%==1 (
237+
set /p "webhookURL=Enter the Discord webhook URL: "
238+
) else (
239+
set "webhookURL="
240+
)
215241
REM Confirm user choices
216242
cls
217243
echo .............................................
@@ -230,7 +256,7 @@ echo # Configuration File Version > .\config\StartupScript.conf
230256
echo configVersion=%currentConfigVersion%>> .\config\StartupScript.conf
231257
echo # >> .\config\StartupScript.conf
232258
echo # --------------------------------------------------------------------------------------------------------------------------- >> .\config\StartupScript.conf
233-
echo # Change the values in the section below >> .\config\StartupScript.conf
259+
echo # General Server Options >> .\config\StartupScript.conf
234260
echo # --------------------------------------------------------------------------------------------------------------------------- >> .\config\StartupScript.conf
235261
echo # >> .\config\StartupScript.conf
236262
echo # Define server file name here >> .\config\StartupScript.conf
@@ -251,6 +277,19 @@ echo. >> .\config\StartupScript.conf
251277
echo # Set console title here >> .\config\StartupScript.conf
252278
echo Title=Minecraft Server >> .\config\StartupScript.conf
253279
echo. >> .\config\StartupScript.conf
280+
echo # --------------------------------------------------------------------------------------------------------------------------- >> .\config\StartupScript.conf
281+
echo # Discord Webhook Options >> .\config\StartupScript.conf
282+
echo # --------------------------------------------------------------------------------------------------------------------------- >> .\config\StartupScript.conf
283+
echo # Follow the "Making a Webhook" section here: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks>> .\config\StartupScript.conf
284+
echo. >> .\config\StartupScript.conf
285+
echo # Set the Discord webhook URL here >> .\config\StartupScript.conf
286+
echo webhookURL=%webhookURL%>> .\config\StartupScript.conf
287+
echo. >> .\config\StartupScript.conf
288+
echo # Set the message which is sent via webhook when the server stops >> .\config\StartupScript.conf
289+
echo webhookMessageStop=```\uD83C\uDFC1 The server has stopped.```>> .\config\StartupScript.conf
290+
echo. >> .\config\StartupScript.conf
291+
echo # Set the message which is sent via webhook when the server stops >> .\config\StartupScript.conf
292+
echo webhookMessageStart=```\uD83D\uDE80 The server has started.```>> .\config\StartupScript.conf
254293
echo Config variables successfully saved to StartupScript.conf
255294

256295
REM Write Java Args to .\config\jvm_args.txt

0 commit comments

Comments
 (0)