Home > Enterprise >  Formatting json text in discord.py bot
Formatting json text in discord.py bot

Time:07-13

@client.command()
async def show(ctx, player, *args):  # General stats
    rs = requests.get(apiLink   "/checkban?name="   str(player))
    if rs.status_code == 200:  # HTTP OK
        rs = rs.json()
        joined_array = ','.join({str(rs["otherNames"]['usedNames'])})
        embed = discord.Embed(title="Other users for"   str(player), 
        description="""User is known as: 
        """  joined_array)
        await ctx.send(embed=embed)

enter image description here

My goal here is to have every username on different lines after each comma, and preferably without the [] at the start and end. I have tried adding joined_array = ','.join({str(rs["otherNames"]['usedNames'])}) but the response from the bot is the same as shown in the image.

Any answer or tip/suggestion is appreciated!

CodePudding user response:

Try this:

array = ['user1', 'user2', 'user3', 'user4', 'user5', 'user6'] #your list
new = "" # output

for i in range(len(array)):
    new  = array[i]
    if (i != len(array) - 1):
        new  = ",\n"
        
print(new)

In your case I think array should be replaced with rs["otherNames"]['usedNames']

  • Related