\n\n\n\n My First Useful Discord Bot: A Simple How-To - Bot-1 \n

My First Useful Discord Bot: A Simple How-To

📖 11 min read2,098 wordsUpdated Mar 18, 2026

Hey everyone, Taylor Quinn here, your guide through the fascinating world of bots over at bot-1.net! Today, I want to talk about something that often trips up aspiring bot builders, something I definitely wrestled with when I first started out: the deceptive simplicity of a “simple” bot. Specifically, how to build your very first, truly useful, and utterly basic Discord bot without getting lost in the weeds of API documentation or advanced programming concepts. We’re talking about a bot that does one thing well, and helps you learn the ropes without feeling overwhelmed. Forget the fancy AI chatbots for now; we’re starting with the fundamentals.

It’s March 2026, and it feels like everyone is talking about AI and complex automation. But before you can run a marathon, you need to learn to walk, right? And for bots, walking means understanding the core loop: input, process, output. I remember my own first bot. It was… ambitious. I tried to make it play music, moderate chat, and tell jokes, all at once. The result? A buggy mess that barely worked and left me feeling more frustrated than enlightened. If only I’d focused on just one tiny thing.

So, today, we’re going to build a “Hello, Bot!” bot for Discord. But it won’t just say hello. It will respond to a specific command, fetch a random fun fact from a pre-defined list, and post it in the chat. This is a fantastic first project because it covers several key concepts:

  • Setting up a bot application.
  • Connecting to a platform (Discord, in this case).
  • Listening for messages.
  • Parsing commands.
  • Generating a response.
  • Sending a message back.

Why Discord? And Why a Fun Fact Bot?

Discord is a brilliant platform for bot beginners. Its API is well-documented, there’s a huge community for support, and it’s free to get started. Plus, you can instantly see your bot in action in a server with friends, which is incredibly motivating. As for the fun fact bot, it’s simple because it doesn’t require any external API calls (beyond Discord’s own). All the “data” is right there in your code, making it easy to understand the flow without worrying about network requests and error handling from other services.

My own journey started with a Discord bot that would just repeat whatever I said back to me, but in all caps. It was silly, but it taught me the basics of message listening and responding. The fun fact bot is just a tiny step up from that, adding a little more logic and variability.

Step 1: Setting Up Your Discord Bot Application

This is where many people get stuck, so pay close attention! You don’t write any code yet, but you set up the “identity” of your bot.

  1. Go to the Discord Developer Portal and log in with your Discord account.
  2. Click “New Application” in the top right. Give it a name like “MyFirstFunFactBot” (you can change this later).
  3. Once created, navigate to the “Bot” tab on the left sidebar.
  4. Click “Add Bot.” Confirm the pop-up.
  5. Under “Privileged Gateway Intents,” make sure to enable “MESSAGE CONTENT INTENT.” This is CRUCIAL as of late 2022; without it, your bot won’t be able to read message content. Seriously, I spent an hour debugging this once, thinking my code was broken!
  6. Copy your “TOKEN.” This is like your bot’s password. Keep it secret! We’ll use it in our code.
  7. Now, we need to invite your bot to a server. Go back to the “OAuth2” tab, then “URL Generator.”
  8. Under “SCOPES,” select “bot.”
  9. Under “BOT PERMISSIONS,” select “Send Messages.” This is all our bot needs for now.
  10. Copy the generated URL and paste it into your browser. Select a server you manage (or a private test server) and authorize your bot.

Phew! That’s the administrative part done. Your bot now exists in Discord’s ecosystem, waiting for your code to bring it to life.

Step 2: Getting Your Environment Ready

For this project, we’ll use Python because it’s super readable and has an excellent library for Discord bots.

  1. Make sure you have Python installed (version 3.8+ is recommended). You can download it from python.org.
  2. Open your terminal or command prompt.
  3. Create a new folder for your project: mkdir funfact_bot && cd funfact_bot
  4. Install the Discord Python library: pip install discord.py
  5. Create a new file called bot.py (or whatever you like) in your project folder.

Step 3: Writing the Code – The Core Logic

Now for the fun part! Open bot.py in your favorite code editor (VS Code, Sublime Text, etc.) and let’s write some Python.

A Simple Discord Bot That Gives Fun Facts

Here’s the complete code. I’ll break it down right after.


import discord
import os
import random

# For security, store your bot token as an environment variable
# If you're just testing, you can paste it directly, but this is better practice.
# Example: export BOT_TOKEN='YOUR_BOT_TOKEN_HERE' in your terminal
# Or create a .env file and use a library like python-dotenv
# For absolute beginners, let's keep it simple for now and directly paste.
# But remember, for anything serious, use environment variables!
BOT_TOKEN = "PASTE_YOUR_BOT_TOKEN_HERE" # <--- REPLACE THIS WITH YOUR ACTUAL BOT TOKEN!

# Define intents
intents = discord.Intents.default()
intents.message_content = True # Enable message content intent

# Initialize the bot client
client = discord.Client(intents=intents)

# Our list of fun facts
fun_facts = [
 "Honey never spoils. Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible.",
 "A group of owls is called a parliament.",
 "The shortest war in history was between Britain and Zanzibar on August 27, 1896. Zanzibar surrendered after 38 minutes.",
 "Banging your head against a wall burns 150 calories an hour.",
 "The average person walks the equivalent of three times around the world in their lifetime.",
 "It is impossible for most people to lick their own elbow.",
 "There are more possible iterations of a game of chess than there are atoms in the known universe.",
 "A crocodile cannot stick its tongue out.",
 "Slugs have four noses.",
 "A 'jiffy' is an actual unit of time: 1/100th of a second.",
]

# Event: Bot is ready
@client.event
async def on_ready():
 print(f'We have logged in as {client.user}')
 print(f'Bot ID: {client.user.id}')
 print('Bot is ready to receive commands!')

# Event: Message received
@client.event
async def on_message(message):
 # Ignore messages from ourselves
 if message.author == client.user:
 return

 # Check if the message starts with our command prefix
 if message.content.startswith('!fact'):
 # Get a random fact from our list
 fact = random.choice(fun_facts)
 # Send the fact back to the channel
 await message.channel.send(fact)

# Run the bot
client.run(BOT_TOKEN)

Code Breakdown

Let’s go through this line by line, so you understand what’s happening. No magic here, just code!

  • import discord: This brings in the discord.py library we installed.
  • import os and import random: os is for potentially handling environment variables (though we’re simplifying that for a true beginner here), and random is to pick a random fact.
  • BOT_TOKEN = "PASTE_YOUR_BOT_TOKEN_HERE": THIS IS WHERE YOU PASTE THE TOKEN YOU COPIED FROM THE DISCORD DEVELOPER PORTAL. Seriously, don’t forget this! In a real project, you’d use os.getenv('BOT_TOKEN') and store the token in an environment variable or a .env file. But for your very first bot, directly pasting it is acceptable for learning, as long as you understand the security implications and don’t share your code publicly with the token in it.
  • intents = discord.Intents.default() and intents.message_content = True: This tells Discord which types of events your bot wants to receive. The message_content intent is crucial for your bot to actually read the text of messages users send.
  • client = discord.Client(intents=intents): This creates our bot client, essentially the object that will connect to Discord.
  • fun_facts = [...]: Our simple list of strings. This is your bot’s “database” for now. You can add as many as you like!
  • @client.event async def on_ready():: This is an “event listener.” It’s a special function that discord.py calls when the bot successfully connects to Discord. It’s a great place to print a confirmation message. The async and await keywords are part of Python’s asynchronous programming, which discord.py uses heavily. Don’t worry too much about the deep mechanics now, just know that many Discord operations are “awaitable.”
  • @client.event async def on_message(message):: This is the core of our bot! This function runs every time a message is sent in any channel your bot can see.
  • if message.author == client.user: return: This is a critical check. Without it, your bot would respond to its own messages, creating an infinite loop of fun facts (or errors!).
  • if message.content.startswith('!fact'):: This checks if the message content begins with our command prefix !fact. You can change this to anything you like, e.g., !tellmeafact.
  • fact = random.choice(fun_facts): If the command is detected, we pick one random fact from our list.
  • await message.channel.send(fact): This is how your bot sends a message back. It sends the chosen fact to the same channel where the !fact command was issued.
  • client.run(BOT_TOKEN): This line starts your bot and keeps it running, listening for events.

Step 4: Running Your Bot

Save your bot.py file. Open your terminal, navigate to your project folder (where bot.py is), and run:


python bot.py

If all goes well, you should see output like:


We have logged in as MyFirstFunFactBot#1234
Bot ID: 123456789012345678
Bot is ready to receive commands!

Now, go to your Discord server where you invited the bot. In any channel, type !fact and press Enter. Your bot should respond with a random fun fact!

Congratulations! You’ve just built your very first, truly functional, and useful Discord bot. I remember the thrill of seeing my first bot actually respond. It felt like magic, even though I’d written the code myself.

Troubleshooting Common Issues

  • Bot doesn’t respond:
    • Did you enable “MESSAGE CONTENT INTENT” in the Discord Developer Portal? This is the most common issue.
    • Did you replace "PASTE_YOUR_BOT_TOKEN_HERE" with your actual bot token?
    • Is your bot online in Discord (green circle next to its name)? If not, your script might have an error and isn’t running. Check your terminal for error messages.
    • Did you invite the bot to the correct server?
    • Is the command prefix correct (!fact)?
  • Error messages in terminal: Read them carefully! Python error messages often tell you exactly which line has the problem.

Actionable Takeaways and Next Steps

You’ve done it! You’ve built a “simple” bot. But simple doesn’t mean useless. This fun fact bot is a solid foundation. Here’s what you can do next:

  1. Add more facts: Expand your fun_facts list.
  2. Add more commands:
    • Create a !hello command that just says “Hello there!”
    • Make a !dice command that rolls a random number (e.g., random.randint(1, 6)).
    • Maybe a !coinflip command.

    Each new command is just another if message.content.startswith('!command_name'): block.

  3. Introduce arguments: What if you wanted !dice 6 to roll a 6-sided die, or !dice 20 for a 20-sided die? You’d need to parse the numbers after !dice. This is a great next challenge. (Hint: message.content.split(' ') will help you get parts of the message.)
  4. Learn about Cogs/Extensions: As your bot grows, putting all the code in one file gets messy. discord.py has a system called Cogs for organizing commands into separate files. This is a natural next step for structuring your bot.
  5. Error handling: What if someone types !dice five? Your current bot might crash if it tries to convert “five” to an integer. Learning to gracefully handle unexpected input is crucial.
  6. Explore other libraries: If you want to fetch facts from a real API (like a joke API or a cat fact API), you’d use Python’s requests library. This opens up a whole new world of possibilities for your bot.

Remember, the goal isn’t to build the next ChatGPT on your first try. The goal is to understand the mechanics, feel the satisfaction of seeing your code come alive, and build confidence. This “simple” fun fact bot is a powerful first step into the amazing world of bot development. Keep experimenting, keep learning, and most importantly, have fun!

Until next time, happy bot building!

Related Articles

🕒 Published:

✍️
Written by Jake Chen

AI technology writer and researcher.

Learn more →

📚 Related Articles

Browse Topics: beginners | chatbots | no-code | platforms | tutorials
Scroll to Top