Home - Thundermaker300/RoSharp GitHub Wiki
[!WARNING] This wiki is work in progress and may be outdated. If you'd like to help out, please feel free to let me know on Discord! -Thunder
Welcome to the RoSharp wiki!
Disclaimer
The code samples present on this wiki are meant to show how the RoSharp framework is used. This wiki has various shortcomings in the actual coding environment, such as error catching. Roblox's API can fail for various reasons, including outages, too many requests, etc. The samples provided on this wiki are samples, and do not account for these occurrences -- in other words, you should write your code expecting it to fail.
Authentication
[!TIP] Does your program only authenticate one user? Check out Global Sessions.
.ROBLOSECURITY
Most APIs require authentication. RoSharp handles this in the form of Session
objects. The following uses the .ROBLOSECURITY token to log in to Roblox.
using RoSharp;
string code = ".ROBLOSECURITY_CODE_HERE";
Session session = new Session();
await session.LoginAsync(code); // Awaited as we sign into Roblox.
// If successful, the session is now logged in and can be used for API that requires authentication.
Console.WriteLine(session.AuthUser.Username); // Print the name of the user that is authenticated.
It is not recommended to store .ROBLOSECURITY codes directly in the source, especially if your code will eventually be public to anyone other than yourself. Please keep this in mind and keep your .ROBLOSECURITY code in a safe place.
API Key
If your program relies solely on APIs that use Roblox's Cloud API + API Keys, authentication with the .ROBLOSECURITY token is not necessary. The following example uses API keys and does not log into any specific account.
using RoSharp;
string apiKey = "API_KEY_HERE";
Session session = new Session();
session.SetAPIKey(apiKey); // Does not need awaited as there's no async operation, it just sets the API key internally.
It is not recommended to store API keys directly in the source, especially if your code will eventually be public to anyone other than yourself. Please keep this in mind and keep your API keys in a safe place.
Roblox will automatically de-activate any API keys that are not used in 60 days. There is no way around this. If your program does not use Roblox APIs often, it is encouraged to regularly "ping" an API member with the API key in order to keep it active.
Caching
RoSharp uses an internal caching system for most APIs, which means that the API will not update once it is initially accessed. See more information on the caching page.
Examples
Get User Information
using RoSharp;
using RoSharp.API;
// Authentication is optional for this example and the session does not need to be provided. However, not all information is available to an unauthorized viewer.
User user = await User.FromId(USER_ID_HERE, SESSION_HERE);
// OR
User user = await User.FromUsername(USERNAME_HERE, SESSION_HERE);
Console.WriteLine(user.Username);
Communities
using RoSharp;
using RoSharp.API;
using RoSharp.API.Communities;
// Get Community information
Community community = await Community.FromId(COMMUNITY_ID_HERE, SESSION_HERE);
Console.WriteLine(community.Name);
// Get the member manager for the below examples
MemberManager members = await community.GetMemberManagerAsync();
// Get user's role in a community
Role? userRole = await members.GetRoleInCommunityAsync(USER_HERE); // Object can be substituted for ID and/or username.
if (userRole != null)
{
Console.WriteLine(userRole.Name);
}
// Set user's role in community
await members.SetRankAsync(USER_HERE, ROLE_OBJECT_HERE); // Objects can be substituted for UserId/Username and Role name/ID.
Delete Scam Posts
The following code segment deletes the most recent 100 posts on the community wall that contain the word "ROBUX" (in any capitalization).
using RoSharp;
using RoSharp.Communities;
Community community = await Community.FromId(COMMUNITY_ID_HERE, SESSION_HERE);
foreach (CommunityPost post in await community.GetPostsAsync())
{
if (post.Text.Contains("ROBUX", StringComparison.OrdinalIgnoreCase))
{
await community.DeletePostAsync(post);
Console.WriteLine($"Deletd Post: {post.PostId} by UserId {post.PosterId}");
}
}