Skip to main content

Command Palette

Search for a command to run...

Just Me, Python, and a Discord Bot That Wouldn’t Listen

Updated
4 min read
Just Me, Python, and a Discord Bot That Wouldn’t Listen

I’ve always been fascinated by how Discord bots work. Like — these small pieces of code that sit quietly in your server, listening, responding, sometimes being way too chaotic if you let them.
At some point I thought: “Okay, what if I just built one myself?”

This post is basically me documenting that process — how I created my own bot, the steps to set it up, the roadblocks (because yes, there were quite a few), and some lessons on hosting it for free.

Because bots make servers feel alive.
You can make them do anything — from managing roles to giving daily motivational quotes to just vibing with your community.
For me, it started as a fun experiment, but the more I built, the more I realized how powerful this stuff can be — like actual automation and creativity rolled into one.

Before touching any code, here’s the basic stack I used:

Language: Python (because easy + versatile)

Library: discord.py

Hosting: Render (because it’s one of the few places that lets you host stuff for free)

Uptime Monitoring: UptimeRobot (keeps the bot alive, or at least tries its best)

Environment Management: .env file for the bot token

If you’re more into JavaScript, you can use discord.js — it’s just as good. But I’ll be honest, Python felt easier to manage for this one.

Setting Up the Bot on Discord Developer Portal

Before you even write the code, you need a bot registered on Discord’s side.
Go to Discord Developer Portal, hit “New Application”, name it whatever you want, and create a Bot User from the Bot tab.

You’ll get a TOKEN.
That’s your key to the kingdom — never share it with anyone, never push it to GitHub, and definitely don’t leak it in screenshots (yep, learned that the hard way once).

Now, inside your .env file:

DISCORD_TOKEN=your_token_here

The Core Code (Minimal Bot):

import discord
from discord.ext import commands
import os

TOKEN = os.getenv("DISCORD_TOKEN")

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}")

@bot.command()
async def ping(ctx):
    await ctx.send("Pong 🏓")

bot.run(TOKEN)

Run it locally and that gets your bot’s online.
It replies “Pong 🏓” when you say !ping.

Then I tried adding commands in different files (Cogs), and at first, it looked like everything was wired up properly… until the logs said:
No Cog or async setup() found in commands.movies; skipping.

Turns out, discord.py wanted me to explicitly use async setup functions for each Cog.
I fixed it, redeployed, and boom — everything worked(kinda).

The “Prefill” Problem:

This one confused me for hours.

When I first added slash commands, Discord didn’t show them automatically.
I thought the code was broken, but it wasn’t. The issue was that prefilling doesn’t happen instantly.
You actually need to sync the commands differently for the first time, and then they start appearing in the server after a few minutes.

After getting the basics running, I started splitting commands into Cogs (modular command files).
This keeps everything neat and allows for scalable features.

Example structure:

bot/ ├── main.py ├── commands/ │ ├── vibe.py │ ├── art.py │ ├── songs.py │ └── books.py └── .env

Each Cog has its own command.

Hosting It for Free

Once the bot worked locally, I wanted it to run 24/7 without keeping my PC on.
So I used Render, it’s free, stable enough, and actually decent for Python bots.
You just:

  1. Push your project to GitHub

  2. Link it on Render

  3. Set build command to pip install -r requirements.txt

  4. Start command to python main.py

  5. Add your token in environment variables

And that’s it; your bot’s online.
Except for the part where Render randomly puts your app to sleep when idle (which it will).

Keeping It Alive (Because Render Sleeps)

Free tiers sleep when idle.
To fix that, I added a keep-alive route in my Flask app and pinged it using UptimeRobot or CronJob every 5 minutes.
You can literally make the bot ping itself — it’s kinda poetic.

from flask import Flask
from threading import Thread

app = Flask('')

@app.route('/')
def home():
    return "Bot is running!"

def run():
    app.run(host='0.0.0.0', port=8080)

def keep_alive():
    Thread(target=run).start()

Then just call keep_alive() before running your bot.

Once your bot’s running, the fun part starts.
You can add things like:

  • AI chat commands using APIs (e.g., OpenAI)

  • Random jokes, facts, quotes

  • Server stats dashboard

  • Role-based games or XP system

  • Music streaming

  • Even a small productivity tracker for your server

Honestly, the limit’s just your imagination (and Discord rate limits 💀).


I started this whole thing thinking I’d just make a small helper bot, but it became more of a creative experiment.
There’s something fun about teaching a bot to react, to speak, to exist within a space where your friends hang out.

If you’ve been thinking of making one — do it.
It’ll test your patience, sure, but you’ll learn more about APIs, hosting, and debugging than any tutorial can teach you.