How to host a Discord bot 24/7
1. Prerequisites
Before deploying your bot, make sure you have:
- Square Cloud Account: Create your account via the Registration Page (email, Discord, GitHub or Google).
- Active Plan: A paid plan is required for hosting. Check the pricing here.
2. Source Code Preparation
For Square Cloud to run your bot correctly, it must be organized and contain the dependency definition file.
Python Example (discord.py)
Make sure you have a requirements.txt file in the root of your project:
discord.pyJavaScript Example (discord.js)
Make sure you have a package.json file in the root of your project:
{
"name": "my-discord-bot",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"discord.js": "^14.0.0"
}
}3. Compression and Cleanup (Important)
A common mistake is trying to upload all project files, including cache folders or local dependencies. For a clean and fast deployment, you should create a .zip file containing only the essentials:
- What to INCLUDE:
.pyor.jsfiles, configuration files (.json,.txt), and the dependency file (requirements.txtorpackage.json). - What to EXCLUDE:
node_modules/(Node modules folder)__pycache__/(Python cache).env(Environment variables will be configured in the dashboard).git/or IDE files (such as.vscode/)
4. Deploying Your Bot
There are two main ways to upload your bot to Square Cloud:
Via Dashboard
- Access the Square Cloud Dashboard.
- Click on "New Application".
- Select the zip upload option.
- During upload, you will see fields to configure your Environment Variables (ENVs).
Via CLI
- Install the CLI:
npm i -g @squarecloud/cli- Authenticate via the CLI: run
squarecloud auth login. The CLI shows a code and opens the authorization page in your browser; approve it and the CLI saves its own API key. (In CI, use--tokenor SQUARECLOUD_API_KEY with a key created under My Account > Security.)
squarecloud auth login- Create your configuration file: The configuration file,
squarecloud.configorsquarecloud.app, must be present in your project. - Upload your project:
squarecloud upload- Or if you created a zip file:
squarecloud upload --file <path/to/zip>5. Configuring Environment Variables (ENV)
Never leave your bot's token exposed directly in the code. Use Square Cloud's ENV system to keep your bot secure.
- Dashboard Configuration: In the variables field, define the name (e.g.,
DISCORD_TOKEN) and the value (your token). - Pay attention to values: The dashboard and
squarecloud app env setquote values for you, so type them without quotation marks. Only when setting variables through the VS Code extension or the API should you wrap a value with spaces or shell characters in single quotes yourself. - Example (VS Code extension or API):
VARIABLE_NAME='p@ss word$1'
- Example (VS Code extension or API):
In your code, access the variable like this:
- Python:
os.getenv('DISCORD_TOKEN') - JavaScript:
process.env.DISCORD_TOKEN
6. Lifecycle and Monitoring
After uploading:
- Square Cloud will automatically detect the required runtime based on the chosen main file and install the dependencies.
- Follow the real-time Logs to check if the bot logged in successfully.
Updated on: 10/04/2026
Thank you!
