I would like my leaderboard to split into multiple pages depending on how many users there are. For example, if there are 5 users, only one page remains, instead if there are 23 users it divides them into 3 pages of which the first 2 show 10 users while the last shows the last 3 users left. I've tried many ways and I've gotten to this point where I don't really know what to do. Can you solve? Any method is accepted as long as it works.
@client.command()
async def leaderboard(ctx):
cursor = levelsystem_db.cursor()
cursor.execute("SELECT users.user_level, users.user_xp, users.client_id\nFROM users\nORDER BY users.user_level DESC , users.user_xp DESC")
leaderboard = cursor.fetchall()
embed = discord.Embed(
title=f"Leaderboard del {ctx.guild.name}",
colour=0x003399
)
for i, pos in enumerate(leaderboard, start=1):
lvl, xp, member_id = pos
cursor.execute(f"SELECT xp_level FROM levels WHERE level = {lvl+1}")
xp_level = cursor.fetchall()
xp_level = xp_level[0][0]
member = await client.fetch_user(member_id)
sorted_users = ## get all the members and sort them...
pages = grouper(sorted_users, 10)
print(pages)
embed.add_field(
name=f"{i}. {member.display_name}",
value=f"Livello attuale: {lvl}\n\t\tXP: {xp}/{xp_level}\n",
inline=False
)
await ctx.send(embed=embed)
def grouper(iterable, n, fillvalue=None):
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue)