Answer the question
In order to leave comments, you need to log in
How to sort all servers where there is a bot, by the number of participants?
I need to get all the servers where there is a bot and sort them in descending order by the number of participants. I have a code like this that shows me all the servers.
@Bot.command()
async def listserver(ctx, page: int = 1):
output = ''
guilds = Bot.guilds
pages = math.ceil(len(guilds)/10)
if 1 <= page <= pages:
counter = 1+(page-1)*10
for guild in guilds[(page-1)*10:page*10]:
output += f'{counter}. {guild.name} {len(guild.members)}\n'
counter += 1
embed = discord.Embed(
color=discord.Color.orange(),
description=output,
title='**СПИСОК ГИЛЬДИИ**'
)
embed.set_footer(text=f'Страница {page} из {pages}')
await ctx.send(embed=embed)
else:
await ctx.send('Указанная вами страница не существует')
Answer the question
In order to leave comments, you need to log in
Get the number of server members and compare with all the others, so you can sort it. Or use ready-made methods by type
max()
min()
sorted(bot.guilds, key = lambda g: g.member_count, reverse=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question