This guide takes a working discord.js bot from your computer to a server where it runs 24/7. We'll tidy up the project, move the token out of the code, upload it and start it. The examples use discord.js v14 and Zettako's discord.js hosting, but the same steps work on any Node.js host.
1. Check your project structure
A typical bot looks like this:
my-bot/
├── commands/
├── index.js
├── deploy-commands.js
├── package.json
├── package-lock.json
└── .env (never uploaded to Git)Make sure package.json lists every package your bot uses. If you installed something globally or forgot --save, the server won't have it. Running npm install in a fresh copy of your project is a good test.
2. Move the token out of your code
If your token is written directly in index.js, move it now. Install dotenv with npm install dotenv and create a .env file:
DISCORD_TOKEN=your-token-hereThen load it at the top of your bot:
require('dotenv').config();
const { Client, Events, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, (c) => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.on(Events.Error, (error) => console.error('Client error:', error));
process.on('unhandledRejection', (error) => console.error('Unhandled rejection:', error));
client.login(process.env.DISCORD_TOKEN);Add .env and node_modules to your .gitignore. On Zettako you can also skip the file entirely and set DISCORD_TOKEN as a startup variable in the panel.
3. Only request the intents you need
Each intent makes Discord send you more events and makes your bot cache more data. Slash-command bots often need only Guilds. If you read message content for prefix commands, add GuildMessages and MessageContent, and enable the Message Content intent in the Developer Portal. Privileged intents like GuildMembers and GuildPresences use the most memory, so only add them when you need them.
4. Choose a plan and Node.js version
A new bot runs comfortably on a small plan. Order a discord.js hosting plan, then in the panel pick the Node.js version you develop with. For discord.js v14, a current LTS release is the safe choice.
5. Upload your files
Upload your project through the panel's file manager or with an SFTP client such as FileZilla or WinSCP, using the SFTP details shown in the panel. Leave out node_modules: packages are installed from package.json on the server, which is faster and avoids problems with packages built for your operating system.
6. Set the startup file and start
In the panel's startup settings, set the main file to index.js (or your entry point, such as dist/index.js for TypeScript). Press start. You should see npm install your packages, followed by your "Ready!" message in the console. Your bot is now online 24/7.
7. Register your slash commands
Slash commands are registered with Discord separately from logging in. Run your deploy-commands.js once, either from your own computer or by temporarily setting it as the startup file on the server. You only need to run it again when you add or change commands, not every time the bot starts, because registering on every boot can hit rate limits.
Troubleshooting
- "Cannot find module": the package is missing from
package.json. Install it locally withnpm install nameand upload the updated file. - "An invalid token was provided": the token variable is empty or wrong. Check the variable name and reset the token in the Developer Portal if it has leaked.
- "Used disallowed intents": you requested a privileged intent that isn't enabled in the Developer Portal.
- The bot keeps restarting: read the error just before each restart in the console. It's almost always an unhandled error in one command.
Next, make your bot resilient with our guide to keeping a Discord bot online 24/7.