@bot.command()
@has_permissions(manage_guild=True)
async def setrank(ctx, username, rank: int):
if rank not in [15, 16]:
await ctx.send("Rank must be either 15 or 16.")
return
try:
group = await roblox.get_group(33909219)
member = await group.get_member_by_username(username)
if member is None:
await ctx.send("The user was not found in the group.")
return
current_rank = await member.get_role()
if current_rank in [15, 16]:
await ctx.send(f"User already has a rank {current_rank}.")
else:
await member.setrole(rank)
await ctx.send("Gived.")
except roblox.UserDoesNotExistError:
await ctx.send("User not found in group.")
except Exception as e:
await ctx.send(f"An error has occurred: {e}")
Basically you have your object which is a client, and you say roblox.UserDoesNotExistError, roblox does not have an attribute roblox.UserDoesNotExistError. Instead you should import UserNotFound in your code:
from roblox.utilities.exceptions import UserNotFound
try:
user = await client.get_user_by_username("InvalidUsername!!!")
except UserNotFound:
print("Invalid username!")