Sorry for my code being messy, just getting back into Python after months of not using it.
@client.command()
async def getinfo(ctx, name):
url = f'https://api.mojang.com/users/profiles/minecraft/{name}'
response = requests.get(url)
uuid = response.json()['id']
url2 = f'https://api.hypixel.net/player?key=885e4c42-24d4-443a-93a8-ff25483cd6cc&uuid={uuid}'
response2 = requests.get(url2)
# END POINTS #
getuser = response2.json()['player']['displayname']
getpastuser = response2.json()['player']['knownAliases']
###########
await ctx.send(f'Username: {getuser}\nPast Usernames: {getpastuser}')
This outputs
Username: 35days
Past Usernames: ['UsernameIsntUsed', 'hqcc', '35days']
I want to get rid of the brackets and mini-quotes around the Past usernames part but I have no clue how to, I have looked around and tried many methods and nothing seems to work. Any suggestions and feedback is helpful!
CodePudding user response:
Follow this example I think you will get clear concept and easily will solve your issue.
apples = ["Fuji", "McIntosh", "Red Delicious", "Gala", "Jonagold"]
separator = ", "
print(separator.join(apples))
CodePudding user response:
Use join on the list... in the event that there other types in the list other than string than cast it to string (may not be necessary)
with casting:
getpastuser = response2.json()['player']['knownAliases']
getpastuserstr = ', '.join(str(e) for e in getpastuser)
await ctx.send(f'Username: {getuser}\nPast Usernames: {getpastuserstr}')
without:
getpastuser = response2.json()['player']['knownAliases']
getpastuserstr = ', '.join(getpastuser)
await ctx.send(f'Username: {getuser}\nPast Usernames: {getpastuserstr}')