Get started¶
At the beginning of every ro.py application is the client. The client represents a user's session on Roblox.
To initialize a client, import it from the roblox
module:
from roblox import Client
client = Client()
Great, we've got a client! But how can we use it?
We start by calling await client.get_OBJECT()
where OBJECT
is a Roblox datatype, like a User, Group or Universe.
But wait - if you tried to run code like this:
from roblox import Client
client = Client()
await client.get_user(1)
You would get an error like this:
File "<input>", line 1
SyntaxError: 'await' outside function
This may seem confusing - but this is intended design.
To fix this, we need to wrap our code in an asynchronous function, and then run it with get_event_loop().run_until_complete
, like so:
import asyncio
from roblox import Client
client = Client()
async def main():
await client.get_user(1)
asyncio.get_event_loop().run_until_complete(main())
This is the basic structure of every ro.py application.
Great, our code works - but it's not doing anything yet. Let's print out some information about this user by replacing
the code in main()
with this:
user = await client.get_user(1)
print("Name:", user.name)
print("Display Name:", user.display_name)
print("Description:", user.description)
Great! We now have a program that prints out a user's name, display name, and description. This same basic concept works for other kinds of objects on Roblox, like groups:
group = await client.get_group(1)
print("Name:", group.name)
print("Description:", group.description)