Requirements
alterself requires Python 3.10 or newer. The library relies on structural pattern matching,ParamSpec, and other language features introduced in 3.10 that cannot be polyfilled on older interpreters. You can check your current version with:
pyproject.toml and installed automatically by pip.
Installation
Choose the installation method that fits your workflow.-e (editable mode) links the package directly to the cloned directory. Any changes you make to the source are immediately reflected without reinstalling, which is useful if you want to contribute to alterself or pin to an unreleased commit.
Token Setup
Your Discord user token is a secret credential with full access to your account. You should never hardcode it in a source file. The recommended pattern is to read it from an environment variable at startup:os.environ["DISCORD_TOKEN"] raises a KeyError immediately if the variable is not set, which prevents your selfbot from starting with an empty token and producing confusing errors later. os.environ.get("PREFIX", "!") falls back to ! if you have not set a custom prefix, making the prefix optional to configure.
Set the environment variable in your shell before running the bot:
.env file (excluded from version control via .gitignore) and loading it with a library such as python-dotenv, or use your platform’s native secrets manager.
Logging
alterself uses Python’s standardlogging module. You can control verbosity by passing log_level to bot.run():
logging.INFO is a good default for most use cases. Switch to logging.DEBUG when you are diagnosing unexpected behaviour. It will show you every gateway opcode and outbound HTTP call. Use logging.WARNING in production if you want a clean terminal.
Proxy
If you need to route your selfbot’s traffic through an HTTP or SOCKS proxy, for example to assign a consistent IP address or to work around network restrictions, pass theproxy parameter to the Client constructor:
socks5:// scheme. Leave the parameter unset to connect directly.
Async Entry Point
bot.run() creates and manages its own asyncio event loop, which makes it convenient as a top-level entry point. If you are integrating alterself into a larger async application that already has a running event loop, for example alongside a web server or another async library, use await bot.start() instead:
bot.start() is a coroutine that connects to the gateway and returns only when the connection is closed. If you want to run the selfbot alongside other long-lived coroutines, schedule them with asyncio.gather() or asyncio.create_task() before awaiting bot.start().