How to Style Discord Bot Message Layout with Numbering and Spacing

I’m working on a Discord bot using Python and having trouble getting the output to display the way I want it to look. I need help with formatting the queue display command.

What I want to achieve: I need to add numbered indexes at the beginning of each line, put some indentation before usernames, and create blank lines between each queue entry for better readability.

Here’s my current code:

@client.command(name='list', aliases=['display'], help='Display current waiting list')
async def show_list(ctx):
    waiting_list = fetch_server_list(ctx)
    current_time = datetime.now()
    
    msg_embed = discord.Embed(title='Waiting List', colour = discord.Colour.green())
    if len(waiting_list) == 0:
        content='No users waiting!'
    else:
        items = []
        for item in waiting_list:
            added_time = datetime.strptime(item['timestamp'], '%Y-%m-%d %H:%M:%S') 
            minutes_waiting = (current_time-added_time).seconds / 60

            if item['note']:
                items.append('**{}** *({:.0f} min)*: {}'
                               .format(item['username'], minutes_waiting, item['note']))
            else:
                items.append('**{}** *({:.0f} min)*'
                               .format(item['username'], minutes_waiting))
        content='\n'.join(items)

    field_name = 'People waiting ({})'.format(len(waiting_list))
    msg_embed.add_field(name=field_name, value=content, inline=False)

    await ctx.send(embed=msg_embed)

Right now everything runs together without proper spacing or numbering. How can I modify this to get the formatting I’m looking for?

Your string formatting and joining method is the problem. You need to add numbering and indentation to those items.append() calls. Change your loop to for idx, item in enumerate(waiting_list, 1): then update your append statements with the index and spacing. For numbered format, try f'{idx}. \t**{item["username"]}** *({minutes_waiting:.0f} min)*' - the \t indents before usernames. Replace your final join with content='\n\n'.join(items) to get blank lines between entries. This gives you proper numbering, indentation, and spacing without overcomplicating things.

try using enumerate in your loop and add some newlines. do for i, item in enumerate(waiting_list, 1): then format it like f'{i}. **{item['username']}**' and use ‘\n\n’.join(items) instead of single newlines - that’ll give you the spacing ur after

Change your items construction section. Don’t just append the formatted strings - build each entry with proper numbering and spacing first.

Replace your current loop with: for position, item in enumerate(waiting_list, start=1): then make each entry like this: entry = f"{position}. \n **{item['username']}** *({minutes_waiting:.0f} min)*" - see how there’s a newline after the number and spaces before the username for indentation? Add notes the same way if they exist.

When you join everything, use content = '\n\n'.join(items) to get those blank lines between entries. Build each numbered entry as a multi-line string first, then join them with double newlines - that’s the trick.