How to Create and Configure Your First Discord Bot: Complete Step-by-Step Guide
Master Discord bot setup from scratch: Developer Portal configuration, Privileged Gateway Intents, writing clean Discord.js v14 or Python scripts, and hosting 24/7 on CoalByte.

#Why Running Your Bot in the Cloud is Essential
When building a Discord bot, many creators start by running their script locally on their personal computer. However, local hosting quickly leads to common issues:
- When your computer goes into sleep mode, your bot disconnects.
- Home internet restarts drop the Discord WebSocket connection.
- High electricity consumption and hardware wear from running 24/7.
- Risk of exposing your personal home IP address.
By deploying your bot to CoalByte 24/7 Free Discord Bot Hosting, your bot runs in an isolated container with 3 GB RAM, 1 vCPU, 8 GB SSD, automated crash restarts, and live console monitoring.
Step 1: Create Your Bot on the Discord Developer Portal
- Open your browser and navigate to the Discord Developer Portal.
- Click the New Application button at the top right and enter your bot's name.
- In the left navigation menu, go to Bot.
- Click Reset Token and copy the secret Bot Token. Keep this safe and never share it publicly or commit it to GitHub.
- Scroll down to Privileged Gateway Intents and enable:
- Presence Intent
- Server Members Intent
- Message Content Intent (required if your bot reads prefixes like !ping)
- Go to OAuth2 > URL Generator:
- Check the bot and applications.commands scopes.
- Select the permissions your bot needs (e.g. Send Messages, Read Message History, Embed Links).
- Copy the generated URL and open it in a new tab to invite the bot to your test server.
Step 2: Code Your Bot (JavaScript / Node.js or Python)
#### Option A: Discord.js v14 (Node.js)
Create a package.json:
{
"name": "my-coalbyte-bot",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"discord.js": "^14.17.3",
"dotenv": "^16.4.7"
}
}Create index.js:
const { Client, GatewayIntentBits } = require('discord.js');
require('dotenv').config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.once('ready', () => {
console.log(`✅ Logged in as ${client.user.tag}! Powered 24/7 by CoalByte Cloud.`);
client.user.setActivity('Hosted on CoalByte', { type: 3 }); // Watching
});
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (message.content === '!ping') {
const latency = Date.now() - message.createdTimestamp;
await message.reply(`🏓 Pong! Roundtrip latency is ${latency}ms. WebSocket ping: ${client.ws.ping}ms.`);
}
});
client.login(process.env.DISCORD_TOKEN);#### Option B: discord.py (Python)
Create requirements.txt:
discord.py>=2.4.0
python-dotenv>=1.0.1Create bot.py:
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'✅ Logged in as {bot.user} on CoalByte Cloud!')
await bot.change_presence(activity=discord.Game(name="24/7 on CoalByte"))
@bot.command()
async def ping(ctx):
latency = round(bot.latency * 1000)
await ctx.reply(f'🏓 Pong! Latency is {latency}ms.')
bot.run(os.getenv('DISCORD_TOKEN'))Step 3: Deploy to CoalByte
- Open the CoalByte Free Discord Bot Hosting page or your dashboard, click Create Server, and select Discord Bot Hosting.
- Open the File Manager tab and upload your files (
package.json+index.js, orrequirements.txt+bot.py). - Create a
.envfile in the root directory:
DISCORD_TOKEN=your_copied_secret_token_here- Open the Console tab and start your server.
- The container will automatically install dependencies and launch your bot process in seconds.
Automated Restarts & Monitoring
Your bot is monitored 24/7 by the CoalByte supervisor. If an unhandled promise rejection or API timeout occurs, the container automatically restarts the process within 2 seconds, guaranteeing continuous availability for your server members.
