Skip to content

Instantly share code, notes, and snippets.

@nathan130200
Last active September 25, 2018 16:46
Show Gist options
  • Save nathan130200/44e333b4e166f425789a0a386693437c to your computer and use it in GitHub Desktop.
Save nathan130200/44e333b4e166f425789a0a386693437c to your computer and use it in GitHub Desktop.
Discord Bot Powershell Launch Script
<#
# 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