[Python] How to create an embedded leaderboard using a MySQL database and nextcord?

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    My goal is to make a command that displays a leaderboard showing the top 20 people in the npcs table, sorted by xp. I've tried pulling the rows but I'm not sure how to display multiple different entries on one line.

    The idea I have would look something like this.

    import mysql.connector
    import nextcord

    @bot.command()
    async def leaderboard(ctx):
    guild = ctx.guild.id

    cursor.execute(f"SELECT * FROM `npcs` WHERE guild = {guild} ORDER BY xp DESC LIMIT 20")

    embed=Embed(title="Top 20 Shinobi")
    embed.add_field(
    name="",
    value=f"1. {npc1} \n2. {npc2} \n3. {npc3} \n4. {npc4} \n5. {npc5} \n6. {npc6} \n7. {npc7} \n8. {npc8} \n9. {npc9} \n10. {npc10} \n11. {npc11} \n12. {npc12} \n13. {npc13} \n14. {npc14} \n15. {npc15} \n16. {npc16} \n17. {npc17} \n18. {npc18} \n19. {npc19} \n20. {npc20}"
    )
    await ctx.send(embed=embed)


    The {npc} things are just filler because I don't know what I would put there to get my desired result. But that's what I imagine when I think of how to do this. Ideally this is what it would display.

    Example Command Output

    This is the table that this data should be pulled from.

    Table

    I haven't been able to find a lot of information on this specific topic, so anything you can think of would be greatly appreciated.

    Continue reading...

Compartilhe esta Página