How to Add Line Spacing and Numbering to Discord Bot Messages

I’m currently developing a Discord bot using Python and encountering some issues with how the output is formatted. Specifically, I’m looking to update my queue display command so that each entry shows a number before the username and includes appropriate spacing between the entries.

At the moment, the bot’s output displays the queue entries all in a line with no numbers. I would like to incorporate index numbers such as 1, 2, 3 before each username and include some space to separate each user in the list.

Here’s the code I’m working with:

@bot.command(name='list', aliases=['displayqueue'], help='Display current user queue')
async def show_user_queue(ctx):
    user_queue = fetch_server_queue(ctx)
    current_time = datetime.now()
    
    message_embed = discord.Embed(title='Current Queue', colour = discord.Colour.green())
    if len(user_queue) == 0:
        content='No users in queue!'
    else:
        queue_items = []
        for item in user_queue:
            join_time = datetime.strptime(item['timestamp'], '%Y-%m-%d %H:%M:%S') 
            waiting_time = (current_time-join_time).seconds / 60

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

    field_name = 'Queue Members ({})'.format(len(user_queue))
    message_embed.add_field(name=field_name, value=content, inline=False)

    await ctx.send(embed=message_embed)

The current output is quite cramped and not easy to read. I would appreciate any suggestions on how to integrate numbering and spacing to enhance its organization.

just wrap your user_queue loop with enumerate() and use the index. change it to for i, item in enumerate(user_queue, 1): then add {}. at the start of your format strings with the index number. works perfectly for numbering.

Fix the spacing by adding extra newlines between entries. Use ‘\n\n’.join(queue_items) instead of ‘\n’.join(queue_items) - gives you better visual separation. For numbering, just modify your loop to track position manually or use enumerate like mentioned above. I’ve found that adding markdown formatting like '{}. ’ at the start of each entry makes the numbers pop more in Discord embeds. You could also add padding characters or use Discord’s code block formatting with triple backticks for a table look, but you’ll need to adjust your string formatting to keep everything aligned.

I’ve built similar queue systems and found you can get much cleaner formatting with proper indexing and smart whitespace.

When I hit this same problem, I changed how queue_items gets built - added numbering plus better spacing. Skip enumerate and try something like {:2d}. **{}** *({:.0f} min)* instead. The {:2d} gives you right-aligned numbers that look professional even with double digits.

For spacing, use Discord’s markdown better. Thin space characters or \n with a zero-width space gives you way more control than just double newlines.

One heads up - Discord caps embed field values at 2048 characters. If your queue gets long, you’ll need pagination or truncation to avoid errors.