Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client Bot Username #106

Open
Vitlyr opened this issue Nov 6, 2023 · 5 comments
Open

Client Bot Username #106

Vitlyr opened this issue Nov 6, 2023 · 5 comments

Comments

@Vitlyr
Copy link

Vitlyr commented Nov 6, 2023

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
@zmadie
Copy link
Contributor

zmadie commented Nov 7, 2023

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

@Vitlyr
Copy link
Author

Vitlyr commented Nov 8, 2023

Thanks for your help! In v2, is there still a way to promote/demote/set-rank users in groups?

@zmadie
Copy link
Contributor

zmadie commented Nov 9, 2023

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

@Vitlyr
Copy link
Author

Vitlyr commented Nov 9, 2023

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.

@Vitlyr
Copy link
Author

Vitlyr commented Nov 20, 2023

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants