Skip to main content
This guide walks you through everything you need to go from a blank Python file to a running alterself selfbot. By the end you will have alterself installed, your Discord token retrieved securely, and a working bot that responds to a .ping command with live latency data. The whole process takes about five minutes.
1

Install alterself

Make sure you have Python 3.10 or newer, then install alterself from PyPI:
Verify the installation by checking the version:
You should see the current version number printed to your terminal. If you see a ModuleNotFoundError instead, double-check that you are running the pip that belongs to the Python interpreter you intend to use.
2

Retrieve your Discord token

alterself connects to Discord as your user account, so it needs your personal user token: not a bot token.
  1. Open Discord in your web browser (discord.com) and log in.
  2. Press F12 (or Cmd + Option + I on macOS) to open DevTools.
  3. Click the Application tab, then expand Storage → Local Storage in the left sidebar.
  4. Click the https://discord.com entry to open the key/value table.
  5. Find the row with the key token and copy its value. That value is your token.
Your user token is the master key to your Discord account. Never paste it into a chat message, commit it to a Git repository, or share it with anyone. Store it in an environment variable (see the Installation guide for details). If you accidentally expose your token, change your Discord password immediately. Discord will invalidate the old token.
3

Create your first selfbot

Create a new file called bot.py and paste in the following code, replacing YOUR_USER_TOKEN with the token you copied in the previous step:
bot.py
Here is what each part does:
  • alterself.Client: the central object that owns the gateway connection, the HTTP session, and the spoofing engine.
  • prefix = ".": every message starting with . will be checked against your registered commands.
  • @bot.on_event / on_ready: runs once the gateway handshake is complete and bot.me is populated.
  • @bot.command() / ping: registers .ping as a command. ctx.reply() sends a message in the same channel.
  • bot.run(): starts the event loop, connects to the gateway, and blocks until you stop the process.
4

Run it and verify

Start the selfbot from your terminal:
You should see output similar to this within a few seconds:
Now open Discord, navigate to any channel your account can write in, and send .ping. The selfbot will reply with something like:
Press Ctrl + C in your terminal to stop the selfbot gracefully.

What to try next

Now that your selfbot is running, here are the natural next steps:
  • Understand the Client: learn about the gateway lifecycle, session state, and the properties available on bot.me in the Client concept guide.
  • Build more commands: explore argument parsing, error handling, and checks in the Commands concept guide.
  • See real examples: browse complete, copy-paste-ready selfbot scripts in the Examples guide.
Store your token in the DISCORD_TOKEN environment variable rather than hardcoding it in bot.py. Replace token = "YOUR_USER_TOKEN" with token = os.environ["DISCORD_TOKEN"] and run export DISCORD_TOKEN=your_token_here in your terminal before starting the bot. Your token will never appear in source code.