A small Python script that randomly starts or stops a game via Steam, and notifies you via a Discord webhook.
- Detects whether a given process (your game) is running.
- Starts the game via its Steam URL if it’s not already running.
- Stops the game after a 2-minute delay, if it is running.
- Sends “Game started” / “Stopping game in 2 minutes” notifications to a Discord webhook.
- Randomly chooses between starting or stopping each time it runs.
- Windows (script uses
os.startfile
to launch Steam URLs). - Python 3.x
- A valid Discord webhook URL.
- The Steam protocol URL for your game (e.g.
steam://rungameid/570
). - The process name of your game’s executable (e.g.
dota2.exe
).
git clone https://github.com/drogers0/random_server.git
cd random_server
# Using built-in venv (Python 3.x)
python -m venv venv
# On Windows PowerShell:
.\venv\Scripts\Activate.ps1
# On Windows CMD:
.\venv\Scripts\activate.bat
pip install -r requirements.txt
In the project root, create a file named:
env.py
Populate it with these three variables:
# env.py
# 1) Your Discord webhook URL.
# Create one in your server: Server Settings → Integrations → Webhooks → New Webhook.
WEBHOOK_URL = "https://discord.com/api/webhooks/…"
# 2) The process name (EXE) of your game. Start the game, and then use ps in powershell and look for the ProcessName of your game.
# e.g., "PalServer", etc.
PROCESS_NAME = "your_game_executable"
# 3) The Steam protocol URL for launching the game.
# You can find it in Steam by right-clicking the game → Properties → General → Launch Options.
# Or use your game’s AppID: steam://rungameid/#####
STEAM_URL = "steam://rungameid/123456"
Once your venv is active and env.py
is configured, just run:
python random_server.py
Each run will randomly choose to start or stop the game, and will send an appropriate Discord notification.
To run this script hourly:
# 1) Open PowerShell **as Administrator** and cd into your repo:
cd C:\path\to\random_server
# 2) Run the scheduler script to create/update the task:
.\schedule_task.ps1
# You should see:
# Scheduled task 'RandomServer' created: runs random_server.py every hour.
# 3) Verify it exists (optional):
Get-ScheduledTask -TaskName RandomServer | Format-List *
# 4) To cancel and remove the task entirely:
Unregister-ScheduledTask -TaskName RandomServer -Confirm:$false
# 5) (Optional) Double-check removal:
Get-ScheduledTask -TaskName RandomServer
# → Should return “No scheduled tasks found.”