statistics.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:aryas 作者: lattkkthxbbye 项目源码 文件源码
def users(self, ctx: commands.Context, count=10):
        """
        Show users with the most messages
        """
        count = count
        # Show at least 1 user and 20 at most
        count = max(1, count)
        count = min(20, count)

        try:
            server = self.orm.Server.get(discord_id=ctx.message.server.id)
        except DoesNotExist as e:
            # If there's no server in the db an exception will be raised
            self.config.logger.error(e)
        else:
            users = await self.orm.query.user_top_list(count, server)
            embed = discord.Embed(color=discord.Color(self.config.constants.embed_color),
                                  timestamp=datetime.datetime.now())
            for user in users:
                # the user might not have a name if s/he hasn't sent a message already
                # so in that case use the id instead
                name = user.name if user.name != '' else user.discord_id
                embed.add_field(name=name, value='Total messages: {}'.format(user.count), inline=False)

            await self.bot.say(content='Top active users:', embed=embed)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号