FreeGameHost.xyz

How to Make a Discord Bot and Host It Free 24/7 (Python & Node.js)

By FreeGameHost Team  •  Updated April 2026  •  10 min read

Discord bots can automate moderation, play music, track server stats, run games, and much more. The best part? Making a Discord bot is easier than most people think — and hosting it 24/7 for free is simple with FreeGameHost.

This guide covers everything from creating your Discord application to writing your first bot commands in both Python and Node.js, all the way to hosting your bot free 24/7 so it stays online even when your computer is off.

Contents

  1. Create a Discord application
  2. Write a bot in Python (discord.py)
  3. Write a bot in Node.js (discord.js)
  4. Host your Discord bot free 24/7
  5. Useful bot commands to add
  6. FAQ

Step 1 — Create a Discord application

Before you write any code, you need to register your bot with Discord.

1.1
Go to the Discord Developer Portal

Visit discord.com/developers/applications and log in with your Discord account.

1.2
Create a new application

Click New Application, give it a name (this will be your bot's name), and click Create.

1.3
Add a Bot

In the left sidebar, click Bot, then click Add Bot. Confirm the action. You can optionally set an avatar for your bot here.

1.4
Copy your bot token

Click Reset Token and copy the token shown. This is your bot's password — keep it secret and never share it publicly.

1.5
Enable Privileged Intents

Scroll down on the Bot page and enable Server Members Intent and Message Content Intent. These are required for most bots to read messages and user data.

1.6
Invite the bot to your server

Go to OAuth2 → URL Generator. Select bot and applications.commands as scopes. Select the permissions your bot needs (Administrator for full access). Copy the generated URL and open it to add your bot to a server you manage.

Important: Never share your bot token. If it gets leaked, reset it immediately in the Developer Portal. Anyone with your token has full control of your bot.

Step 2a — Write a Discord bot in Python

Python is the most beginner-friendly option for Discord bots. We'll use discord.py, the most popular Python Discord library.

Install discord.py

If you're testing locally first, open a terminal and run:

pip install discord.py

Basic bot example (Python)

Create a file called bot.py and paste this code:

Python
import discord
from discord.ext import commands

# Replace with your actual bot token
TOKEN = 'YOUR_BOT_TOKEN_HERE'

intents = discord.Intents.default()
intents.message_content = True
intents.members = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
    print(f'Bot is online as {bot.user}')

@bot.command()
async def hello(ctx):
    await ctx.send(f'Hello, {ctx.author.mention}! 👋')

@bot.command()
async def ping(ctx):
    latency = round(bot.latency * 1000)
    await ctx.send(f'Pong! Latency: {latency}ms')

@bot.command()
async def serverinfo(ctx):
    guild = ctx.guild
    await ctx.send(
        f'Server: {guild.name}\n'
        f'Members: {guild.member_count}\n'
        f'Created: {guild.created_at.strftime("%Y-%m-%d")}'
    )

bot.run(TOKEN)

This bot responds to three commands: !hello, !ping, and !serverinfo. To test locally, run python bot.py in your terminal.

Using slash commands (recommended for new bots)

Discord now recommends slash commands over prefix commands. Here's how to add them:

import discord
from discord import app_commands

TOKEN = 'YOUR_BOT_TOKEN_HERE'

intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)

@tree.command(name='ping', description='Check bot latency')
async def ping(interaction: discord.Interaction):
    latency = round(client.latency * 1000)
    await interaction.response.send_message(f'Pong! {latency}ms')

@client.event
async def on_ready():
    await tree.sync()
    print(f'Logged in as {client.user}')

client.run(TOKEN)

Step 2b — Write a Discord bot in Node.js

If you prefer JavaScript, discord.js is the most popular and well-documented option.

Set up your project

mkdir my-discord-bot
cd my-discord-bot
npm init -y
npm install discord.js

Basic bot example (Node.js)

Create a file called index.js:

JavaScript
const { Client, GatewayIntentBits } = require('discord.js');

const TOKEN = 'YOUR_BOT_TOKEN_HERE';

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers,
  ]
});

client.once('ready', () => {
  console.log(`Bot is online as ${client.user.tag}`);
});

client.on('messageCreate', async (message) => {
  if (message.author.bot) return;

  if (message.content === '!hello') {
    await message.reply(`Hello, ${message.author}!`);
  }

  if (message.content === '!ping') {
    const latency = Math.round(client.ws.ping);
    await message.reply(`Pong! Latency: ${latency}ms`);
  }

  if (message.content === '!serverinfo') {
    const guild = message.guild;
    await message.reply(
      `Server: ${guild.name}\nMembers: ${guild.memberCount}`
    );
  }
});

client.login(TOKEN);

Run it locally with node index.js to test.

Tip: Store your bot token in an environment variable rather than hardcoding it. Create a .env file with TOKEN=your_token_here and use the dotenv package to load it. This prevents accidentally committing your token to GitHub.

Step 3 — Host your Discord bot free 24/7

Once your bot works locally, you need to host it so it stays online 24/7 — even when your computer is off. FreeGameHost offers free Discord bot hosting for both Python and Node.js bots.

3.1
Create a free account

Sign up at panel.freegamehost.xyz. No credit card required.

3.2
Create a Discord bot server

Click Create Server and select Discord Bot as the server type. Choose Python or Node.js to match your bot's language.

3.3
Upload your bot files

Use the File Manager in your control panel to upload your bot files (bot.py or index.js, plus any other files your bot needs).

3.4
Install dependencies

Open the Console tab in your control panel and run pip install discord.py (Python) or npm install (Node.js) to install your bot's dependencies.

3.5
Set your startup command and start

Set the startup command to python bot.py or node index.js, then click Start. Your bot will come online and stay online 24/7.

Useful bot commands to add next

Once your basic bot is running, here are some popular commands to add:

Frequently asked questions

Do I need to know how to code to make a Discord bot?
Some basic programming knowledge helps, but Python is beginner-friendly and there are many tutorials available. If you want a bot without coding, consider using a no-code bot like MEE6 or Carl-bot instead.
Is Python or Node.js better for Discord bots?
Both work great. Python (discord.py) is better for beginners and those with data science or scripting backgrounds. Node.js (discord.js) is better if you already know JavaScript or plan to build more complex bots. Both are fully supported on FreeGameHost.
How do I keep my Discord bot online 24/7 for free?
Host it on FreeGameHost. You get 512MB RAM and 25% CPU dedicated to your bot, running 24/7 at no cost. Upload your code, install dependencies, and start the bot. It stays running even when your computer is off.
Can my bot be in multiple servers?
Yes. A single Discord bot can be in unlimited servers. Just generate a new invite link for each server you want to add it to.
How do I add a database to my Discord bot?
SQLite works great for small bots and requires no setup. For larger bots, consider using a free tier from PlanetScale or Supabase (PostgreSQL). Connect to your database from your bot code using a library like aiosqlite (Python) or better-sqlite3 (Node.js).

Ready to host your Discord bot free 24/7?

Get Free Discord Bot Hosting →

Related: Free Discord Bot Hosting  •  Free Minecraft Server Hosting