How to Host a 24/7 Discord Bot (Node.js & Python)
Running a Discord bot on a home computer or free tier host often leads to rate limits, sleep timeouts, and unexpected downtime. Ash Host provides containerized Discord bot hosting with continuous uptime, automated crash restarts, and instant package installation for both Node.js and Python bots.
.env file.Method A: Hosting a Node.js Bot (discord.js)
1. Prepare Your Bot Files
Ensure your project directory contains your main entry file (usually index.js or bot.js) and a valid package.json file defining your dependencies.
{
"name": "my-discord-bot",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "^14.14.0",
"dotenv": "^16.3.1"
}
}
2. Upload Files to Ash Host Panel
- Log in to the Ash Host Game Panel and select your bot container.
- Go to the Files tab.
- Upload your project files (e.g.,
index.js,package.json, commands folder). Do not upload thenode_modulesfolder; the panel will install dependencies automatically.
3. Configure Startup Settings
- Navigate to the Startup tab on the left menu.
- Verify the Main File field is set to match your entry point (e.g.,
index.js). - Verify the Node.js Version matches your code requirements (Node 18 or Node 20 recommended for discord.js v14).
4. Install Dependencies & Start
- Go to the Console tab and click Start.
- The container will automatically execute
npm install, download required packages, and launch your bot. - Check the console log to verify your bot has logged in successfully:
Ready! Logged in as MyBot#1234
Method B: Hosting a Python Bot (discord.py / nextcord)
1. Prepare Your Python Files
Your bot directory must contain your entry file (e.g., main.py or bot.py) and a requirements.txt file listing all required Python libraries:
discord.py>=2.3.0
python-dotenv>=1.0.0
aiohttp>=3.9.0
2. Upload and Run
- Go to the Files tab in the Ash Host Game Panel.
- Upload
main.py,requirements.txt, and your bot assets. - Go to the Startup tab and ensure the Main File is set to
main.py. - Return to the Console tab and click Start. The panel will run
pip install -r requirements.txtinside your virtual container and launch the bot.
Managing Bot Tokens Securely
To update or rotate your bot token without editing script files:
- Go to the Files tab and create a file named
.env. - Add your bot credentials:
DISCORD_TOKEN=MTAyNDU5...your_actual_token_here... CLIENT_ID=123456789012345678 - In your Node.js or Python script, reference the token via
process.env.DISCORD_TOKENoros.getenv('DISCORD_TOKEN').
Frequently Asked Questions
Will my bot shut down when I close my browser?
No. Ash Host bot containers run inside isolated Docker instances that operate 24/7 on our enterprise servers, independent of your local machine.
What happens if the bot encounters an uncaught exception?
Ash Host containers are set to auto-restart on unexpected crashes, minimizing bot downtime.
Was dit antwoord nuttig?
Gerelateerde artikelen
Powered by WHMCompleteSolution