Hey guys! So I was making a board for my group with members and the shout on it, I used the member counter tutorial and it worked, but I was wondering if it was possible to get the shout as well? If so I’d love to hear how!
Great, ok, so as you may or may not know we use a python module called ro_py.
Now, if we look inside our RankingAPI/main.py at main · CookieHax/RankingAPI (github.com) file we can see:
@app.get("/group/members/")
async def read_items(key: str, groupid: int):
if key == APIKEY:
group = await client.get_group(groupid)
return (group.member_count)
else:
return "Incorrect key"
What this code does is check when a request is sent, and then checks the key, and gets the group Id. Then it calls the group and gets the data of the group and puts it into the variable “group”. Following this it returns the “group.member_count”.
If you can understand this we can edit it to return different data.
You can see in the ro_py documentation we can see all the data that we get from the group variable, we can also get the shout with “group.shout”.
So, if you go to your repository on github, click on “main.py” and click on the pencil button.
Do ctrl + A and then the Backspace button.
(This should remove all the code that was there.)
Then copy and paste this new code in:
from fastapi import FastAPI
import os
import requests
from ro_py.client import Client
from dotenv import load_dotenv
import asyncio
load_dotenv()
import json
RobloxCookie = os.getenv("COOKIE")
APIKEY = os.getenv("API_KEY")
client = Client(RobloxCookie)
app = FastAPI()
@app.get("/group/promote/")
async def read_items(user_name: str, key: str,groupid: int):
if key == APIKEY:
group = await client.get_group(groupid)
usernameinsystem = await client.get_user_by_username(user_name)
user_id = usernameinsystem.id
membertorank = await group.get_member_by_id(user_id)
await membertorank.promote()
return ("The user was promoted!")
else:
return "Incorrect key"
@app.get("/group/demote/")
async def read_items(user_name: str, key: str, groupid: int):
if key == APIKEY:
group = await client.get_group(groupid)
usernameinsystem = await client.get_user_by_username(user_name)
user_id = usernameinsystem.id
membertorank = await group.get_member_by_id(user_id)
await membertorank.demote()
return ("The user was demoted!")
else:
return "Incorrect key"
@app.get("/group/rank/")
async def read_items(user_name: str, key: str, groupid: int, role_number: int):
if key == APIKEY:
group = await client.get_group(groupid)
target = await group.get_member_by_username(user_name)
await target.setrole(role_number)
return ("The user had their ranked changed")
else:
return "Incorrect key"
@app.get("/group/members/")
async def read_items(key: str, groupid: int):
if key == APIKEY:
group = await client.get_group(groupid)
return (group.member_count)
else:
return "Incorrect key"
@app.get("/group/shout/")
async def read_items(key: str, groupid: int):
if key == APIKEY:
url = 'https://groups.roblox.com/v1/groups/'
group = requests.get(url + str(groupid))
data = json.loads(group.text)
getShoutData = data['shout']
print(getShoutData['body'])
return (getShoutData['body'])
else:
return "Incorrect key"
If you need any help linking it to your board in roblox or you have any problems tell me.
I still need to fix the code up a bit, so I will update this post later, as this code still has a bit of a problem, but then it will be fixed.
Thank you! This will help.
Keep in mind that script I sent you won’t work yet, it’s just an example, I will give you the working script tomorrow.
Oh, alrighty then. That’s fine.
I think I almost have an idea.
Alright! Take your time.
Alright, just updated this post.
Make a new topic if you need help linking it to roblox, make sure to link this post in the new post (if you make it)!
Thanks! This worked like a charm.
This topic was automatically closed after 7 days. New replies are no longer allowed.