Client Bot Username
Vitlyr opened this issue · 5 comments
So I have this code, where it tries to find-out the bots username, it returns with AttributeError: 'Client' object has no attribute 'user'
, is there a way to fix this?
from fastapi import FastAPI, Request, HTTPException, APIRouter
from fastapi.responses import HTMLResponse
import os
import requests
import ro_py
from ro_py.client import Client
from dotenv import load_dotenv
load_dotenv()
RobloxCookie = os.getenv("COOKIE")
client = ro_py.Client(RobloxCookie)
router = APIRouter()
async def get_bot_username():
bot_username = client.user.name
return bot_username
@router.get("/bot/username", response_class=HTMLResponse)
async def about(request: Request):
bot_username = await get_bot_username()
return bot_username
Use Client.get_self to get a PartialUser then access the .name
attribute
async def get_bot_username():
bot_username = (await client.get_self()).name
return bot_username
Also, consider updating to v2 (roblox
), because v1 (ro_py
) is slowly breaking. With v2 your code would look like this (using Client.get_authenticated_user):
async def get_bot_username():
bot_username = (await client.get_authenticated_user()).name
return bot_username
Thanks for your help! In v2, is there still a way to promote/demote/set-rank users in groups?
Use either MemberRelationShip.set_role (pick a role from BaseGroup.get_roles and pass it to the method) or MemberRelationShip.set_rank. I wouldn't recommend using a promote/demote method because of this:
they kind of suck - you should just do group.get_roles and then pick the role you want, then do set_role.
promoting blindly to "the role above" is kind of bad because if you ever rearrange the roles it breaks things silently
but if you want to regardless you could copy the code here into (non-method) functions and adapt it to v2
Could this potentially work out?
from Roblox import Client
from fastapi import FastAPI, Body
app = FastAPI()
@app.post("/promote")
async def promote(user_id: int, group_id: int):
client = Client()
client.promote_group_member(group_id, user_id)
return {"message": "User has been promoted."}
@app.post("/demote")
async def demote(user_id: int, group_id: int):
client = Client()
client.demote_group_member(group_id, user_id)
return {"message": "User has been demoted."}
@app.post("/set-rank")
async def set_rank(user_id: int, group_id: int, rank: int):
client = Client()
client.set_group_member_rank(group_id, user_id, rank)
return {"message": "User's rank has been set."}
Edit: it seems that v1 doesn't function on getting the bots info, but v2 does. Replying to this response.
Never mind, looking at it further, it seems that that won't work out unless I create a function with the name, "promote" and "demote".