Answer the question
In order to leave comments, you need to log in
How to make top balance for discord bot?
Hello, please tell me how to make a command for the discord bot that will display the top balance of the server?
I have a code that displays my balance, but how can I make the bot display the top balance of all players?
@client.command()
async def balance(ctx, member: discord.Member = None):
await ctx.channel.purge( limit = 1 )
if member is None:
await ctx.author.send(embed = discord.Embed(
description = f"""**{ctx.author}** ваш баланс составляет **{cursor.execute("SELECT cash From users WHERE id = {}".format(ctx.author.id)).fetchone()[0]} :dollar:**"""
))
else:
await ctx.author.send(embed = discord.Embed(
description = f"""Баланс пользователя **{member}** составляет **{cursor.execute("SELECT cash From users WHERE id = {}".format(member.id)).fetchone()[0]} :dollar:**"""
))
Answer the question
In order to leave comments, you need to log in
@client.command(aliases = ['leaderboard', 'lb'])
async def __leaderboard(ctx):
embed = discord.Embed(title = 'Top 10 Members')
counter = 0
for row in cursor.execute("SELECT name, cash FROM users WHERE id = {} ORDER BY cash DESC LIMIT 10".format(ctx.guild.id)):
counter += 1
embed.add_field(
name = f'# {counter} | `{row[0 ]}`',
value = f'Balance: {row[1]}',
inline = False
)
await ctx.send(embed = embed)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question