BabiiMuffin
BabiiMuffin

Reputation: 31

Formatting Discord Bot Output

I'm dabbling with Python and JS trying to making some specific commands for a Discord Bot. I'm running some into some issues formatting what I want it to look like. Does anyone by chance know what I'm missing?

Goal: Add index values in front and an indent before the username. Also, add a line spacing between each entry.

@bot.command(name='qs', aliases=['showqueue'], help='Show the current queue')
async def queue_show(ctx):
    queue = get_guild_queue(ctx)
    now = datetime.now()
    
    embed = discord.Embed(title='Queue', colour = discord.Colour.blue())
    if len(queue) == 0:
        value='The queue is empty!'
    else:
        entries = []
        for entry in queue:
            joined = datetime.strptime(entry['datetime'], '%Y-%m-%d %H:%M:%S') 
            wait_min = (now-joined).seconds / 60

            if entry['msg']:
                entries.append('**{}** *({:.0f} min)*: {}'
                               .format(entry['name'], wait_min, entry['msg']))
            else:
                entries.append('**{}** *({:.0f} min)*'
                               .format(entry['name'], wait_min))
        value='\n'.join(entries)

    name = 'Users in the queue ({})'.format(len(queue))
    embed.add_field(name=name, value=value, inline=False)

    await ctx.send(embed=embed)

What it currently looks like:

The goal:

Upvotes: 3

Views: 1843

Answers (1)

Mattwmaster58
Mattwmaster58

Reputation: 2579

Indenting can be achieved by simply adding some amount of spaces in front of the entries. If this doesn't work (Discord may truncate leading space), try using a tab character:

entries.append('\t**{}** *....[truncated]
                ^^

For the index, I'd use the enumerate function which gives yields a tuple of the index and element when given an iterator as input. Here's a simple example using a print function, which can be applied to your case.

for index, entry in enumerate(queue):
    # add one as index starts at 0
    print(index + 1, entry)

Upvotes: 2

Related Questions