A framework for building bots for Root (rootapp.com). It runs a normal user account headlessly as a bot: Bearer-token auth over grpc-web, polled text-chat commands, and LiveKit voice. A complete music bot built on the framework is included as the reference example, the framework itself is bot-agnostic.
The docs carry a done/deferred mapping for the engineering standard this codebase is reviewed against.
- Use a throwaway account, never your main. The bot is the account it runs as: a normal Root user account, driven headlessly. Give it a dedicated alt with nothing paid attached and nothing you would miss. If the account is banned or lost, everything attached to it is gone with it.
- The token is a full login. The Bearer token this framework
runs on can do anything the account can do. Treat it like a
password: keep it in the environment or in a
.envfile that is never committed, never paste it into chats, logs or issue reports, and treat the account as compromised if the token leaks. - YouTube paths carry YouTube's rules. The music example reaches YouTube through a Lavalink sidecar and yt-dlp, and that use is subject to YouTube's Terms of Service; direct access from server IPs is bot-checked, which is why the sidecar and a burner Google account exist. What you fetch and play is your responsibility.
- Live streams are not supported. The direct-URL fetcher rejects playlists (HLS/DASH) and the provider routes cannot play live streams either, so live streams do not play. Whether and how live support should work is an open, undecided question; ordinary tracks and recorded streams are unaffected.
Unofficial project, not affiliated with Root Communications, Inc.
You need Python 3.11 or newer and git. Voice playback also needs ffmpeg on the PATH.
1. ffmpeg (only for voice playback):
Windows (PowerShell):
winget install Gyan.FFmpegmacOS / Linux (bash):
sudo apt install ffmpegOn macOS, brew install ffmpeg works too.
2. Clone and install:
Windows (PowerShell):
git clone https://github.com/driannsa/root-bot-framework
cd root-bot-framework
py -m venv .venv
.venv\Scripts\Activate.ps1
pip install .macOS / Linux (bash):
git clone https://github.com/driannsa/root-bot-framework
cd root-bot-framework
python3 -m venv .venv
source .venv/bin/activate
pip install .3. Check the setup:
Windows (PowerShell):
rootbot doctormacOS / Linux (bash):
rootbot doctorrootbot doctor runs the setup checks and then stops. Without a
token it reports [RB-E001] (no token found); that is the
expected result at this point, not a failure of the install.
4. Create your first bot:
Windows (PowerShell):
rootbot new mybot
cd mybotmacOS / Linux (bash):
rootbot new mybot
cd mybotTo run it, get a token with the token capture guide, set it, and serve the skeleton (stop it with Ctrl+C):
Windows (PowerShell):
$env:ROOT_TOKEN=<redacted>
rootbot serve bot.pymacOS / Linux (bash):
export ROOT_TOKEN=<redacted>
rootbot serve bot.pyrootbot.core.bot,Bot: the framework core. Owns the client, multi-community discovery and the polling loop;@bot.commanddecorator with typedContext, argument converters, per-user cooldowns, aliases, owner-only commands and auto-generated help;@bot.eventhooks (on_ready,on_message,on_voice_join/on_voice_leavevia presence diffing,on_tick,on_shutdown); a middleware pipeline around dispatch. Handler errors are contained - the loop never dies from a command.rootbot.core.models, typed dataclasses (Message,Channel,Community,User,Member,Role,VoiceMember,Track) that also support dict-style access.rootbot.errors,RootBotErrorhierarchy (AuthError,APIError,NotFoundError,ConfigError,TokenMissingError,ConversionError).rootbot.config,BotConfig+ loading:ROOT_TOKENfrom the environment or a.envfile, optional JSON config, validated.rootbot.adapters.root.client,RootApi: authenticated calls to api.rootapp.com (GetSelf, ListMine/GetExtended discovery, chat List/Create/Edit/Delete/Pin, voice presence, SessionCreate), with bounded retries (exponential backoff + jitter) on transient failures.rootbot.adapters.root.chat,ChatWatcher: polls every watched channel, primes a seen-ID set at startup, routes messages per community.rootbot.core.cache, bounded LRU entity cache for users, channels, communities and members.rootbot.core.middleware, middleware pipeline support, with logging and rate-limit middleware included.rootbot.core.converters, argument converters (5mdurations, int, float, bool, raw string).rootbot.core.text, long-message splitting (plain text only; the framework never generates mention markup).rootbot.logging, stdlib logging setup with a redaction filter that strips Bearer tokens and registered secrets from log records.rootbot.testing,FakeRootApi+FakeClockfor writing bot tests with no network and no sleeping.rootbot.adapters.root.wire, minimal protobuf + grpc-web framing, GUID codec.examples/musicbot/music.py,Lavalinkclient: track resolve/search and the audio stream endpoint of a Lavalink sidecar with the youtube-source plugin (direct YouTube access from a server IP does not work).rootbot.voice.player,Player: joins the LiveKit room from a SessionCreate reply and publishes a mic track fed by ffmpeg PCM, with pause and volume. Voice is an optional integration, not part of the core Bot, the core skeleton is voice-free; only the music example uses this module.examples/musicbot/, the music bot itself (serve loop + commands), written only against the library above.examples/echobot/,examples/modbot/, minimal bots proving the framework is not music-specific.
The whole framework in one file (examples/echobot/echobot.py):
from rootbot.core.bot import Bot
bot = Bot()
@bot.event
async def on_ready(bot):
print(f"echobot ready as {bot.self_id}")
@bot.command("ping")
async def ping(ctx):
await ctx.reply("pong")
@bot.command("echo")
async def echo(ctx):
await ctx.reply(ctx.args or "say what?")
if __name__ == "__main__":
bot.run()Run it with the alt's token in the environment:
ROOT_TOKEN=<token> python3 -m examples.echobot.echobotBot() reads the token from ROOT_TOKEN or a .env file, discovers
every community the account belongs to, and polls them all. Commands
get a typed Context (message, author, channel, community, parsed
args, converters like ctx.arg_duration(0) for 5m-style values).
Add brief=/usage= to a command and the built-in !help lists it;
add cooldown=30 for a per-user cooldown; wrap dispatch with
bot.use(...) middleware. Full tutorial:
Write your own bot.
- A Root alt account (throwaway, nothing paid attached, see limits).
- A Linux VPS (Ubuntu) with Python 3.11+, ffmpeg, Java 17+, curl.
- A burner Google account for the Lavalink YouTube OAuth step.
- The alt's Bearer token, captured once from the real client
(see
deploy/capture/README.md).
- Capture the token: follow
deploy/capture/README.md(Proxifier + mitmproxy, system proxy OFF, CA in the user store, ~20 s in voice). - Configure: copy
.env.exampleto.envand setROOT_TOKEN; copyconfig.example.jsontoexamples/musicbot/config.json(the ids are only a fallback, serve discovers the alt's communities automatically). - Set up Lavalink: see
deploy/lavalink/README.md, build the youtube-source plugin jar, writeapplication.yml, and do the one-time OAuth device-code approval with the burner account. - Deploy:
bash deploy/deploy.sh root@your-vps(override the SSH command withROOTBOT_SSH=...if plain ssh cannot reach the box). This installs a venv, systemd units for the bot and Lavalink, and starts both. - Run manually instead:
bash examples/musicbot/serve.sh.
!play <url or search> (search shows a top-5 picker, playlists enqueue
whole), !pause, !resume, !skip, !stop, !queue, !np, !vol <0-100>, !loop <off|track|queue>, !shuffle (smart, artist-spread),
!autoplay (YouTube Mix refill), !remove <n>, !clear, !ping,
!help. The bot joins the voice channel the command author is sitting in
(follow-me), only takes commands from members of its voice channel while
playing, and leaves after 5 idle minutes.
For the 0.x line the promise is light, and it covers three
surfaces: the public API (the top-level rootbot exports plus
the documented submodules), config keys, and the rootbot
CLI's flags. Patch releases never break any of them. A break
may land only at a minor bump, and only for something that
shipped a deprecation warning one release ahead naming the
replacement and the removal version. The plugin contract has
its own mechanism (PLUGIN_API_VERSION).
rootbot.testing is provisional: its doubles may change
in any release, including a patch release.
Two stubbed suites (no network, no LiveKit), 232 checks total:
python3 tests/test_serve.py, 150 checks: wire parsing of ListMine, watcher routing, follow-me, shuffle, autoplay, cards, playback loop.python3 tests/test_framework.py, 82 checks: converters, middleware order/veto, cooldowns on a fake clock, auto-help, aliases, owner-only commands, log redaction, client retries, the entity cache, unknown payload fields, message splitting, written againstrootbot.testing(FakeRootApi,FakeClock).
Quality gates (also in CI): ruff format --check, ruff check, and
mypy rootbot/ (strict-ish) all pass.
.env (see .env.example): ROOT_TOKEN, the alt's session Bearer
token. LAVALINK_PASSWORD, Lavalink server password; if empty, read from
the file named by LAVALINK_PASSWORD_FILE. One of the two must be set:
there is no default password file, and the music bot refuses to start
without one (RB-E014).
LAVALINK_BASE, Lavalink REST base (default http://127.0.0.1:2333).
ROOTBOT_CONFIG, explicit path to the bot config JSON.
config.json (see config.example.json): community_id / container_id
- home community and default voice channel, used as the join fallback and
as the discovery fallback seed.
communities, fallback list of{id, name}used only when API discovery returns nothing.
- Root's Terms of Use (effective February 19, 2026) do not permit reverse engineering of the Service (Section 2.2) or the use of a robot, spider, or other automated device to monitor or copy the Service (Section 2.5). Root may suspend access without notice (Section 1.3) or terminate it immediately (Section 13). A bot-user account can be banned; use a throwaway alt with nothing paid attached, and never your main account.
- Bearer token lifetime is unknown (hours at least). When it dies the log
fills with poll errors; recapture and replace
ROOT_TOKEN. - Chat is plain text only, a user account cannot send real embeds, so
the bot formats embed-style text cards instead. The framework only
ever sends plain text (it never generates mention markup), and long
replies are split automatically at
message_limit(default 2000 chars; Root's real limit is unknown, so the default is conservative). - Root is pre-1.0 and changes fast; field numbers in
client.pycome from the 0.9.167 client and may need re-mapping after updates.