Last active
September 25, 2018 16:46
-
-
Save nathan130200/44e333b4e166f425789a0a386693437c to your computer and use it in GitHub Desktop.
Discord Bot Powershell Launch Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
# Discord Bot Powershell Launch Script | |
#> | |
$BotWorkingDir = [environment]::CurrentDirectory | |
$BotName = "MyBot" | |
<# | |
# BotType = 1: .NET Core bot. | |
# BotType = 0: .NET Framework (.exe) bot. | |
#> | |
$BotType = 1 | |
function Start-Bot | |
{ | |
param | |
( | |
[String] | |
$Command | |
) | |
Write-Output "[$BotName] Running bot [$BotType] with command: $Command..." | |
while($true) | |
{ | |
try | |
{ | |
Start-Process -FilePath "$Command" -NoNewWindow -WorkingDirectory $BotWorkingDir -Wait | |
} | |
catch | |
{ | |
Write-Output "[$BotName] Failed to create bot process! `n" $_ | |
break; | |
} | |
if($LASTEXITCODE -eq 0) | |
{ | |
Write-Output "[$BotName] Bot exited cleanly! Quitting." | |
break; | |
} | |
else | |
{ | |
Write-Output "[$BotName] Bot exited non-cleanly! Waiting 5s then restarting..." | |
Start-Sleep -Seconds 5 | |
} | |
} | |
} | |
if($BotType -eq 1) | |
{ | |
Start-Bot -Command "dotnet `"$BotWorkingDir\$BotName`"" | |
} | |
else | |
{ | |
Start-Bot -Command "`"$BotWorkingDir\$BotName`"" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment