def stats(self, ctx):
"""Shows some general statistics about the bot.
Do not confuse this with `{prefix}about` which is just the
general info. This is just numbers.
"""
bot = self.bot
command_map = itertools.starmap('{1} {0}'.format, bot.command_counter.most_common())
command_stats = '\n'.join(command_map) or 'No stats yet.'
extension_stats = '\n'.join(f'{len(set(getattr(bot, attr).values()))} {attr}'
for attr in ('cogs', 'extensions'))
with self.process.oneshot():
memory_usage_in_mb = self.process.memory_full_info().uss / 1024**2
cpu_usage = self.process.cpu_percent() / psutil.cpu_count()
uptime_seconds = bot.uptime.total_seconds()
average_messages = bot.message_counter / uptime_seconds
message_field = f'{bot.message_counter} messages\n({average_messages :.2f} messages/sec)'
text, voice = partition(lambda c: isinstance(c, discord.TextChannel), bot.get_all_channels())
presence = (f"{bot.guild_count} Servers\n{ilen(text)} Text Channels\n"
f"{ilen(voice)} Voice Channels\n{bot.user_count} Users")
chiaki_embed = (discord.Embed(description=bot.appinfo.description, colour=self.bot.colour)
.set_author(name=str(ctx.bot.user), icon_url=bot.user.avatar_url)
.add_field(name='Modules', value=extension_stats)
.add_field(name='CPU Usage', value=f'{cpu_usage}%\n{memory_usage_in_mb :.2f}MB')
.add_field(name='Messages', value=message_field)
.add_field(name='Presence', value=presence)
.add_field(name='Commands', value=command_stats)
.add_field(name='Uptime', value=self.bot.str_uptime.replace(', ', '\n'))
)
await ctx.send(embed=chiaki_embed)
评论列表
文章目录