Running a Discord bot on a Windows server
Here's how to connect to a Windows server with Remote Desktop and run a Discord bot 24/7. We assume your bot code already runs fine on your PC. For a Linux server, see Hosting a Discord bot 24/7 (discord.js, discord.py).
1. Move your bot files
Compress your bot folder and copy it over Remote Desktop (Uploading and downloading files), or if it's on GitHub, download it on the server. Here we'll assume it's in C:\mybot.
🔒 Don't write your bot token directly in your code; keep it separately in a
.envfile. If the token leaks, anyone can control your bot.
Node.js bot (discord.js)
Install Node.js
In a browser on the server, go to nodejs.org, download the Windows .msi of the LTS version, and install it. Open a new PowerShell window to check.
node -v
Install packages and run
cd C:\mybot
npm install
node index.js
If your bot comes online in Discord, it worked. (Replace index.js with your bot's start file name.)
Python bot (discord.py)
Install Python
Download the Windows installer from python.org and run it. On the first screen, be sure to check "Add python.exe to PATH" before installing.
Create a virtual environment and run
cd C:\mybot
py -m venv venv
.\venv\Scripts\pip install -r requirements.txt
.\venv\Scripts\python bot.py
Restart when it stops, and start automatically after a reboot
If you just run the bot yourself, it won't come back on after it stops because of an error. Create C:\mybot\start.bat so it runs again automatically when it stops.
@echo off
cd /d C:\mybot
:loop
node index.js
echo Bot stopped. Restarting in 10 seconds...
timeout /t 10
goto loop
For a Python bot, change the node index.js line to venv\Scripts\python bot.py.
To have the bot start automatically even after the server reboots, register this start.bat in Task Scheduler. Just follow Running programs automatically on a Windows server as written.
Good to know
- Close the Remote Desktop window with the X button. If you sign out inside the server, a bot you started yourself will shut down.
- A bot isn't a program that accepts connections from outside, so you don't need to open any firewall ports.
- If your bot shuts down, check the last error message in the console window. Token errors and missing packages are the most common causes.
- Windows itself uses a lot of memory. If you're only running a bot, a Linux server is cheaper and lighter. Operating system selection guide