[Audio] Fix issue on audiostats command when more than 20 servers to display (#2533)

* Update audio.py

* Fix of pages counter.
This commit is contained in:
PredaaA 2019-04-18 18:12:16 +02:00 committed by Will
parent 0652dd344b
commit ad06b0e723

View File

@ -547,8 +547,8 @@ class Audio(commands.Cog):
"""Audio stats."""
server_num = len([p for p in lavalink.players if p.current is not None])
total_num = len([p for p in lavalink.players])
server_list = []
msg = ""
for p in lavalink.players:
connect_start = p.fetch("connect")
connect_dur = self._dynamic_time(
@ -558,40 +558,40 @@ class Audio(commands.Cog):
if "localtracks/" in p.current.uri:
if p.current.title == "Unknown title":
current_title = p.current.uri.replace("localtracks/", "")
server_list.append(
"{} [`{}`]: **{}**".format(
msg += "{} [`{}`]: **{}**\n".format(
p.channel.guild.name, connect_dur, current_title
)
)
else:
current_title = p.current.title
server_list.append(
"{} [`{}`]: **{} - {}**".format(
msg += "{} [`{}`]: **{} - {}**\n".format(
p.channel.guild.name, connect_dur, p.current.author, current_title
)
)
else:
server_list.append(
"{} [`{}`]: **[{}]({})**".format(
msg += "{} [`{}`]: **[{}]({})**\n".format(
p.channel.guild.name, connect_dur, p.current.title, p.current.uri
)
)
except AttributeError:
server_list.append(
"{} [`{}`]: **{}**".format(
msg += "{} [`{}`]: **{}**\n".format(
p.channel.guild.name, connect_dur, _("Nothing playing.")
)
)
if server_num == 0:
servers = _("Not connected anywhere.")
else:
servers = "\n".join(server_list)
embed = discord.Embed(
if total_num == 0:
return await self._embed_msg(ctx, _("Not connected anywhere."))
servers_embed = []
pages = 1
for page in pagify(msg, delims=["\n"], page_length=1500):
em = discord.Embed(
colour=await ctx.embed_colour(),
title=_("Playing in {num}/{total} servers:").format(num=server_num, total=total_num),
description=servers,
title=_("Playing in {num}/{total} servers:").format(
num=server_num, total=total_num
),
description=page,
)
await ctx.send(embed=embed)
em.set_footer(text="Page {}/{}".format(pages, (math.ceil(len(msg) / 1500))))
pages += 1
servers_embed.append(em)
await menu(ctx, servers_embed, DEFAULT_CONTROLS)
@commands.command()
@commands.guild_only()