Quick answer
- Include a
package.json; the server runsnpm installon every start. - Load the token from
.envwith dotenv. - Set the bot file (default
index.js) on the Startup page and press Start.
Project files#
{
"name": "my-bot",
"type": "module",
"dependencies": {
"discord.js": "^14.16.0",
"dotenv": "^16.4.0"
}
}import "dotenv/config";
import { Client, Events, GatewayIntentBits } from "discord.js";
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, (c) => console.log(`Logged in as ${c.user.tag}`));
client.on(Events.InteractionCreate, async (i) => {
if (i.isChatInputCommand() && i.commandName === "ping") await i.reply("pong");
});
client.login(process.env.DISCORD_TOKEN);Register slash commands#
Slash commands are registered once with Discord's REST API, separate from the bot itself. Add a small script and run it whenever you change commands:
import "dotenv/config";
import { REST, Routes, SlashCommandBuilder } from "discord.js";
const commands = [new SlashCommandBuilder().setName("ping").setDescription("Replies with pong").toJSON()];
const rest = new REST().setToken(process.env.DISCORD_TOKEN);
await rest.put(Routes.applicationCommands(process.env.CLIENT_ID), { body: commands });
console.log("Commands registered");On the server, set the bot file to deploy-commands.js, start it once, then set it back to index.js. Add CLIENT_ID (your application ID) to .env.
Deploy#
- Create the bot server
On free Discord bot hosting, create a server and choose Node.js. Pick the Node version (up to Node 24) on the Startup page; discord.js 14 needs Node 18 or newer.
- Upload or use GitHub
Upload your files with the file manager or SFTP (skip
node_modules), or set Git Repo Address and Git Branch and reinstall. Upload.envby hand. - Start
Press Start. The Console shows
npm install, then "Logged in as ...".
Troubleshooting#
- "Cannot use import statement outside a module": add
"type": "module"to package.json, or userequire. - "Used disallowed intents": turn on the intent in the Developer Portal or remove it from your code.
- Commands don't show: run the deploy script again, and check
CLIENT_ID.
Bot servers don't sleep. Free servers run on a timer: each click on Renew adds 12 hours, up to 48 hours stored, as often as you like. Python instead? See how to host a discord.py bot.
Related: Free Discord Bot Hosting • Free Minecraft Server Hosting
Frequently asked questions#
Which Node.js version do I need?
discord.js 14 needs Node 18 or newer. The bot server lets you pick Node versions up to 24.
Do I upload node_modules?
No. Upload package.json; the server runs npm install on every start.
How do I update the bot from GitHub?
Set the Git repo and branch on the Startup page and turn on Auto Update. Every restart pulls the latest code.



