This guide covers how to interact with the Pokemon Showdown battle simulator using the Node.js API.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.
Basic Setup
Creating a Battle
The simulator usesBattleStream as its primary interface:
Teams must be provided in packed format for non-random formats.
Writing to the Simulator
All messages written to the simulator must start with>. Lines without > are treated as comments.
Start Command
Initialize a battle with format options:OPTIONS is a JSON object with these properties:
The format ID (e.g.,
"gen9ou", "gen9randombattle")Array of four numbers for PRNG seed (defaults to random)
Player 1 options (alternative to separate
>player p1 command)Player 2 options (alternative to separate
>player p2 command)Player 3 options for 4-player battles
Player 4 options for 4-player battles
Example
Player Command
Set player information:PLAYERID is p1, p2, p3, or p4.
PLAYEROPTIONS is a JSON object:
Player name (defaults to “Player 1” or “Player 2”)
Player avatar identifier (defaults to empty string)
Team in packed format or JSON format
Example
Choice Commands
Submit player decisions:CHOICE can be:
move MOVENUM- Use a move (e.g.,move 1)switch POKEMONNUM- Switch Pokemon (e.g.,switch 3)team TEAMORDER- Select team order in Team Preview (e.g.,team 123456)
Example Turn
Reading from the Simulator
The simulator outputs messages delimited by\n\n in text streams, or as separate strings in object streams.
Message Types
- update
- sideupdate
- end
Messages for all players and spectators:Contains battle state updates following the SIM-PROTOCOL format.
Split Messages
Private information is sent using|split|PLAYERID:SECRET- Messages with exact details (e.g., exact HP) for the player or omniscient observerPUBLIC- Messages with public details for opponents/spectators (may be empty)
Complete Example
Here’s a full example with team generation and battle simulation:Advanced Options
BattleStream Options
You can pass options when creating a BattleStream:Seeded Battles
For reproducible battles, provide a seed:Force Commands
You can force battle outcomes:Error Handling
Errors in player choices are sent as|error| messages in sideupdate:
Next Steps
BattleStream API
Deep dive into BattleStream and player streams
Team Formats
Learn about team format conversions
