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.