Commands¶
Running commands¶
api.run_command(":ban m4tty_b Combat logging 7d") # the ':' is optional
api.run_command("kick dxrkrider Exploiting", check=True) # raises CommandFailedError if it didn't work
results = api.run_commands([ # up to 10 at once, run in order
"wanted m4tty_b 2",
"pm m4tty_b You're wanted for robbery",
"radio Police Suspect m4tty_b last seen on Cowley Rd",
])
# Commands wait up to 8 seconds for a result. If one takes longer, it comes back as "Pending".
r = api.run_command("setting CustomVehicles [...]")
if r["Status"] == "Pending":
r = api.wait_for_command(r["CommandId"]) # note: this one uses lower case, e.g. "succeeded"
A command can come back without an error and still have failed, so always check Status.
Code tells you why: OK, TARGET_NOT_FOUND, INVALID_ARGS, FORBIDDEN,
PACKAGE_REQUIRED, RATE_LIMITED, OFFLINE, UNKNOWN_COMMAND or FAILED. Oxford's docs
have the full list of commands.
Command helpers¶
There's also a method for each command, so you don't have to build the text yourself:
api.kick("dxrkrider", "Exploiting")
api.ban("m4tty_b", "Combat logging", "7d") # or timedelta(days=7), or leave it out for permanent
api.wanted("team:Civilian", 0)
api.pm("all", "Server restart in 5 minutes")
api.set_team(81234401, "Police")
api.set_weather("thunderstorm")
api.create_incident("Police", 1, 415, 1238, "Alarm at Oxford Bank")
api.set_setting("TeamLimits", {"Police": 8, "Fire": 4}) # sent as JSON for you
They check your arguments before sending anything. A ban duration like "7 days", a team
that doesn't exist or a wanted level of 5 raises ValueError straight away. Unlike
run_command(), the helpers raise CommandFailedError if the server says the command didn't
work. Pass check=False if you'd rather get the result back and check it yourself.
The full set:
- Moderation:
kick,ban,unban,jail,release,wanted,pmandresolve_modcall. - Staff:
rank,unrank,group_addandgroup_remove. - Players and vehicles:
set_team,respawn,revive,teleport,teleport_to_vehicle,set_invincible,give,despawn_vehicle,remove_vehicle,spawn_vehicle,repairandrefuel. - World and messages:
set_time,lock_time,set_weather,lock_weather,announce,team_announce,alert,set_message,remove_message,countdownandspeed_limit. - Control room:
create_incident,assign_incident,close_incident,radio,start_callout,ambulance_callout,list_calloutsandstop_fires. - Server:
set_setting,new_join_code,queue_remove,queue_front,clear_placeablesandshutdown.
Lots of commands at once¶
run_many() sends any number of commands in order. It batches them 10 at a time and waits
when it needs to, so you stay under the game's limit of 15 commands every 10 seconds:
Keeping staff and groups in sync¶
If your staff ranks or groups should match something else, like Discord roles or a database, tell oxrpy what they should be and it sends only the changes:
# Roblox user ID -> rank name (or None to take them off the staff)
api.sync_staff({81234401: "Mod", 81239912: "Senior Moderator", 77001200: None})
# Make a group contain exactly these user IDs
api.sync_group("CID", [81234401, 81239912])
# See what it would do first, without sending anything
print(api.plan_staff_sync({81234401: "Admin"})) # ['rank 81234401 admin']
It uses user IDs rather than usernames, because a name can change or match the wrong person.
It never touches the owner. sync_staff leaves alone any staff you didn't mention, unless you
pass remove_others=True. sync_group does remove anyone not in your list, unless you pass
remove_others=False.