Search code examples
jsonapidiscord.pyembed

Formatting json text in discord.py bot


@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!


Solution

  • Try this:

    array = ['user1', 'user2', 'user3', 'user4', 'user5', 'user6'] #your list
    new = ",\n".join(array)
    
    print(new)
    

    Output:

    user1,
    user2,
    user3,
    user4,
    user5,
    user6
    

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