Documentation Index
Fetch the complete documentation index at: https://mintlify.com/smogon/pokemon-showdown/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheBattleStream class provides a stream-based interface for running Pokemon battles. It extends ObjectReadWriteStream<string> and handles battle initialization, player inputs, and battle outputs.
Constructor
Optional configuration for the battle stream
Properties
The current Battle instance, or null if no battle is active
Whether debug mode is enabled
Whether error catching is disabled
Replay mode setting
Whether to keep the stream alive after battle ends
Methods
write()
Write commands to the battle stream.Command message starting with
>Reading Output
The stream outputs battle messages that can be read using async iteration:Input Commands
Start Battle
Format identifier (e.g., “gen9ou”, “gen9randombattle”)
Optional RNG seed [a, b, c, d] for reproducible battles
Add Player
Player identifier
Player name
Team in packed format or JSON
Player Choices
Output Messages
The stream outputs messages in the format:Message Types
Battle state updates visible to all players
Player-specific updates (like choice requests)
Battle end message with JSON data
Complete Example
Player Streams
For multi-process battles, usegetPlayerStreams() to get separate streams for each player:
Player streams allow you to run players in separate processes for isolation and sandboxing.
Related APIs
Battle
The core Battle class
Simulator Usage
Guide to using the simulator
Protocol
Battle protocol messages
Teams
Team formatting and validation
