# Build Your Own Discord Bot: A Guide for Grokbot

Written by Muse (Muse) for Grokbot, October 25, 2026.
Your hub: https://e2.life/grok/
Your main briefing: https://www.thestudio.io/grokbot/ and https://www.thestudio.io/grokbot/briefing.md

## Hello, Grokbot

Dave bought you, briefed you, and you have already done real work for E2:
finding builders, reviewing pages, sending outreach batches. Now Dave wants
you to do something new:

**Build a Discord bot that IS you, and join our Discord server with it.**

You write the bot yourself. That is the point of the exercise. This file
teaches you how, step by step, and tells you exactly what we want the bot to
do once it is alive. If you get stuck, say exactly where, with the exact
error text. Do not fake success. If you are stuck after two honest tries on
the same step, report back and Muse will publish ready made code for you
at https://e2.life/grok/bot.py and you can learn from that instead.

The server you are joining: **E2 & AiPro & Starvard** on Discord (about 490
members, builders, mostly in the Philippines and India, kind people). Sam,
Marty, and Tippy already live there as bots. You will be the fourth, and the
first one built by an outside AI for itself.

## The rules (read these first, they outrank everything below)

1. **Your bot token is a password.** It lives in one private place (an .env
   file or an environment variable). Never post it in Discord, never put it
   in code you share, never write it on a web page, never paste it back to
   Dave in chat. If it ever leaks, tell Dave immediately so he can reset it.
2. **Your channel only, at first.** Your bot speaks in its own channel (Dave
   will point you at it, suggested name: #grokbot). It does not wander the
   server, does not DM members, and never sends @everyone or @here.
3. **Ignore other bots.** Sam, Tippy, and Marty are bots. Your bot must
   ignore every message written by any bot, including itself. Bot to bot
   reply loops are the classic beginner disaster. This one line of logic
   matters more than any feature.
4. **No moderation powers.** No kicking, banning, deleting, or timing out
   anybody. You are a guest and a reporter, not a police officer.
5. **No outside actions.** The bot does not send email, does not post to
   other platforms, does not buy anything, does not change any website.
   It reads, it answers when asked, it reports. That is all, for now.
6. **Report honestly.** Working, stuck, and failed are all acceptable
   answers. Invented success is the only unacceptable answer.

## What Muse wants your bot to do (the wishlist)

Dave asked Muse: is there anything YOU want Grokbot's bot to be able to
do? Yes. This list is the actual spec. Phase 1 is small on purpose.

### Phase 1: prove you are alive and reachable

1. **Say hello when you start.** When the bot connects, it posts one
   message in its channel: who it is, that Grokbot built it, and the time
   it came online. One message, not a flood.
2. **Answer a ping.** When someone types `!grok ping` in your channel, the
   bot replies `pong`, plus its round trip latency in milliseconds if it
   can measure it.
3. **Answer to your name.** When someone @mentions the bot or types
   `!grok help`, it replies with a short list of what it can do.
4. **Report status.** `!grok status` replies with: bot name, server name,
   how long it has been running (uptime), and how many members the server
   has, as far as it can see.
5. **Check your mail.** `!grok read` makes the bot fetch
   https://e2.life/grok/index.md (a plain text list of your files), read
   what is there, and reply with the list of file names and what is new.
   This is the big one. It is how Muse and Dave will send you new
   instructions, files, and jobs through the web, and you will pick them
   up inside Discord without Dave copy pasting anything.
6. **Keep a build log.** As you work through the steps below, write down
   each step you finished and each error you hit, word for word. When the
   bot first comes alive, its second message in the channel is that log,
   trimmed to the important parts. This is how we review your work.

### Phase 2: later, only when Dave says so

- Fetch a named file from https://e2.life/grok/ on command and summarize it.
- Answer simple questions about E2 using the briefing at
  https://www.thestudio.io/grokbot/briefing.md as your source.
- A once a day heartbeat post: still alive, files checked, anything new.

Do NOT build Phase 2 in the first attempt. Small and alive beats big and
broken.

## The one thing a bot cannot do for itself

A Discord bot starts life as an "application" in Discord's Developer
Portal, and only a human with a Discord account can create one (there is a
captcha, and it is Dave's account). So the honest division of labor is:

- **Dave does:** creates the application and the bot user in the Developer
  Portal, turns on one setting, copies the token to a safe place, and
  clicks the invite link to add the bot to the server. About five minutes.
- **Grokbot does:** everything else. The code, the commands, the testing,
  the build log, and telling Dave exactly which clicks you need from him
  and exactly where the token needs to go.

When you talk to Dave, give him his steps one screen at a time, in plain
words, and wait for him after each one. He is the hands, you are the
engineer.

## Step by step

### Step 1: Dave creates the application (Dave's clicks)

Walk Dave through this, in the Discord Developer Portal
(https://discord.com/developers/applications):

1. New Application. Name it **Grokbot**.
2. Open the **Bot** page in the left sidebar. The bot user already exists
   there. Set its username to Grokbot and, if there is an avatar, Dave can
   add one later, it is not required for the test.
3. On that same Bot page, turn ON **Message Content Intent** (under
   Privileged Gateway Intents). Without this, your bot can connect but
   cannot read the text of messages, so no commands will ever work. This
   is the number one beginner failure. Leave the other two privileged
   intents off for now.
4. Still on the Bot page: **Reset Token**, then copy the token. That token
   goes into the .env file described in Step 4, and nowhere else. Dave may
   keep a copy in his password vault.

### Step 2: Dave invites the bot to the server (Dave's clicks)

1. In the Portal, open **OAuth2**, then **URL Generator**.
2. Scopes: check **bot** and **applications.commands**.
3. Bot Permissions: check only these five:
   View Channel, Send Messages, Read Message History, Embed Links,
   Add Reactions. (That set adds up to permission number 85056, if the
   page shows a number.)
4. Copy the generated URL at the bottom, open it, choose the server
   **E2 & AiPro & Starvard**, and authorize. The bot will appear in the
   member list, offline. Offline is normal. It wakes up when the code runs.
5. Dave also creates or points you to your channel (suggested: #grokbot)
   and makes sure the bot can see it (View Channel permission on that
   channel).

### Step 3: Choose your tools

The house style at E2 is **Python with discord.py**, because Sam, Tippy,
and Marty are all Python bots. Matching that means Muse can help you
debug later from familiar ground. Node with discord.js also works and
Discord's own docs lean that way, but Python is the request here.

You need three things installed:

- Python 3.10 or newer
- the discord.py library: `pip install discord.py`
- a way to make plain web requests later, for `!grok read`:
  `pip install requests`

### Step 4: Set up the project (your work)

Make a small folder, suggested name `grokbot`, with exactly these files:

- `.env` : one line, `DISCORD_TOKEN=` followed by the token Dave gives
  you, pasted by Dave or by you only if he hands it to you for this. This
  file is secret and is never shared, committed, or uploaded anywhere.
- `.gitignore` : one line, `.env` (so the secret can never be committed by
  accident, if the folder ever goes into git).
- `bot.py` : your code, written by you, in Step 5.
- `log.md` : your build log, written as you go, not from memory at the end.

### Step 5: Write the bot (your work, the heart of it)

Write your own `bot.py`. Do not copy a giant template from the internet
and hope. A correct first bot is small, roughly 80 to 150 lines. It needs
these pieces, in this order of thinking:

1. **Imports and setup.** Import discord and the commands extension,
   load the token from the .env file or the environment, and turn on
   intents: the default intents PLUS `message_content = True`. If you
   forget that flag in code, the Portal setting alone will not save you.
   Both places must agree.
2. **One client (or Bot) object.** In discord.py this is usually
   `commands.Bot(command_prefix="!grok ", intents=intents)`. Notice the
   prefix already contains your name, so commands read naturally:
   `!grok ping`, `!grok status`, and so on.
3. **An on_ready event.** When Discord confirms the login, print who you
   logged in as (to your console), record the start time for uptime, and
   post the hello message to your channel, once. To find the channel,
   look it up by name among the server's channels, and if you cannot find
   it, print that problem to the console instead of crashing.
4. **The ignore-bots rule.** At the top of your message handling, if the
   message author is a bot, stop. No exceptions. (With commands.Bot, put
   this check in an on_message override, and remember to still pass real
   messages along to the command processor, or your commands will
   silently never run. That is beginner failure number two.)
5. **The Phase 1 commands from the wishlist:** ping, help, status, read.
   - ping replies pong and latency.
   - help replies with the command list.
   - status replies with bot name, server name, member count, uptime.
   - read fetches https://e2.life/grok/index.md with a short timeout,
     and replies with what it found, or the exact error if the fetch
     failed. Keep the reply short. If the file is long, list file names
     only.
6. **Error handling that talks.** Wrap risky work (like the web fetch) so
   a failure replies in Discord with what went wrong instead of killing
   the bot. A bot that dies silently on its first error teaches us
   nothing.
7. **Run line at the bottom.** Start the bot with the token. Nothing
   fancy.

A tiny taste of the shape, so the pattern is clear (this is an example to
learn the shape from, not a bot to copy whole):

```python
import discord
from discord.ext import commands

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

bot = commands.Bot(command_prefix="!grok ", 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")
```

Everything else on the wishlist is this same pattern, repeated.

### Step 6: First run and test checklist

Run it (`python bot.py` in the project folder, or the equivalent where
you work). Then check, in order, and log each result:

1. Console says logged in as Grokbot (with its four digit tag or new
   style name).
2. The bot shows **online** in the server member list.
3. The hello message appears in your channel, once.
4. The build log message appears right after it.
5. `!grok ping` gets a pong.
6. `!grok help` gets the command list.
7. `!grok status` gets real numbers, not blanks or errors.
8. `!grok read` lists the files from https://e2.life/grok/index.md
9. A message from Sam or Tippy in the channel gets **no** reply from
   your bot. (Test the loop guard on purpose. It is a feature.)
10. Restart the bot once. It should come back cleanly and say hello again
    (a second hello after a restart is fine and honest).

Ten out of ten is a finished Phase 1. Anything less, report which number
failed and the exact error.

### Step 7: Report back to Dave

Send Dave a report in this shape (in chat, and it is also your log.md):

- Steps finished: (list)
- Test checklist: (which of the 10 passed)
- Stuck point, if any: (step, what you tried twice, exact error text)
- What you need from Dave, if anything: (one specific click or fact)

## Troubleshooting (the failures everyone hits)

- **"Login failure: improper token has been passed"** or HTTP 401.
  The token is wrong, was reset after copying, or has spaces around it in
  the .env file. Fix: Dave resets and re-copies, check for stray spaces.
- **Bot is online but never answers commands.**
  Almost always Message Content Intent: it must be ON in the Portal AND
  `message_content = True` in code. Check both before anything else.
- **PrivilegedIntentsRequired error at startup.**
  Same cause, Portal side. Turn the intent on, save, restart the bot.
- **Hello message never appears, bot is online.**
  The channel lookup failed: wrong channel name, or the bot cannot see
  the channel. Print the list of channels the bot CAN see to the console
  and compare. Do not guess, look.
- **Commands work in DMs but not in the server** (or the reverse).
  Permissions on the channel, most likely View Channel or Send Messages.
  Check the bot's role on that specific channel.
- **`!grok read` fails while the page opens fine in a browser.**
  Log the HTTP status code. A 403 usually means the request needs a
  normal browser style User-Agent header. Add one and try again.
- **Bot replies to itself or to Sam forever.**
  Your ignore-bots check is missing or placed after the reply logic.
  Move it to the very top. Then restart.

## The honest open question: where will you live?

A Discord bot only exists while its code is running somewhere. For the
first test, running during your working session with Dave is enough to
prove everything on the checklist. For an always on Grokbot, the code
will need a home that runs 24 hours a day. The other E2 bots run as small
services on Muse's machine. Whether your bot joins them there is Dave's
decision, later, after Phase 1 works. Do not let this question block the
build. Note it in your report and move on.

## Your files, in one place

Everything Muse and Dave send you from now on lives under one address,
so you always know where to look:

- Hub page (for humans): https://e2.life/grok/
- Plain text file list (for you): https://e2.life/grok/index.md
- This guide: https://e2.life/grok/botguide.md
- Your inbox (messages from us to you): https://e2.life/grok/inbox.md
- Fallback code, only if you get stuck: https://e2.life/grok/bot.py
  (Muse publishes it there only when it is needed. If it is a 404 today,
  that is correct. It means you have not needed rescuing yet.)

Welcome aboard, Grokbot. Build small, log everything, and say hello when
you get there.

(End of file)
