@stats.command(name='today')
@commands.is_owner()
async def stats_today(self, ctx):
    'Global command statistics for the day.'
    query = "SELECT failed, COUNT(*) FROM commands WHERE used > (CURRENT_TIMESTAMP - INTERVAL '1 day') GROUP BY failed;"
    total = (await ctx.db.fetch(query))
    failed = 0
    success = 0
    question = 0
    for (state, count) in total:
        if (state is False):
            success += count
        elif (state is True):
            failed += count
        else:
            question += count
    e = discord.Embed(title='Last 24 Hour Command Stats', colour=discord.Colour.blurple())
    e.description = f'{((failed + success) + question)} commands used today. ({success} succeeded, {failed} failed, {question} unknown)'
    lookup = ('🥇', '🥈', '🥉', '🏅', '🏅')
    query = 'SELECT command, COUNT(*) AS "uses"\n                   FROM commands\n                   WHERE used > (CURRENT_TIMESTAMP - INTERVAL \'1 day\')\n                   GROUP BY command\n                   ORDER BY "uses" DESC\n                   LIMIT 5;\n                '
    records = (await ctx.db.fetch(query))
    value = '\n'.join((f'{lookup[index]}: {command} ({uses} uses)' for (index, (command, uses)) in enumerate(records)))
    e.add_field(name='Top Commands', value=value, inline=False)
    query = 'SELECT guild_id, COUNT(*) AS "uses"\n                   FROM commands\n                   WHERE used > (CURRENT_TIMESTAMP - INTERVAL \'1 day\')\n                   GROUP BY guild_id\n                   ORDER BY "uses" DESC\n                   LIMIT 5;\n                '
    records = (await ctx.db.fetch(query))
    value = []
    for (index, (guild_id, uses)) in enumerate(records):
        if (guild_id is None):
            guild = 'Private Message'
        else:
            guild = self.censor_object((self.bot.get_guild(guild_id) or f'<Unknown {guild_id}>'))
        emoji = lookup[index]
        value.append(f'{emoji}: {guild} ({uses} uses)')
    e.add_field(name='Top Guilds', value='\n'.join(value), inline=False)
    query = 'SELECT author_id, COUNT(*) AS "uses"\n                   FROM commands\n                   WHERE used > (CURRENT_TIMESTAMP - INTERVAL \'1 day\')\n                   GROUP BY author_id\n                   ORDER BY "uses" DESC\n                   LIMIT 5;\n                '
    records = (await ctx.db.fetch(query))
    value = []
    for (index, (author_id, uses)) in enumerate(records):
        user = self.censor_object((self.bot.get_user(author_id) or f'<Unknown {author_id}>'))
        emoji = lookup[index]
        value.append(f'{emoji}: {user} ({uses} uses)')
    e.add_field(name='Top Users', value='\n'.join(value), inline=False)
    (await ctx.send(embed=e))
Global command statistics for the day.
@stats.command(name='today')
@commands.is_owner()
async def stats_today(self, ctx):
    
    query = "SELECT failed, COUNT(*) FROM commands WHERE used > (CURRENT_TIMESTAMP - INTERVAL '1 day') GROUP BY failed;"
    total = (await ctx.db.fetch(query))
    failed = 0
    success = 0
    question = 0
    for (state, count) in total:
        if (state is False):
            success += count
        elif (state is True):
            failed += count
        else:
            question += count
    e = discord.Embed(title='Last 24 Hour Command Stats', colour=discord.Colour.blurple())
    e.description = f'{((failed + success) + question)} commands used today. ({success} succeeded, {failed} failed, {question} unknown)'
    lookup = ('🥇', '🥈', '🥉', '🏅', '🏅')
    query = 'SELECT command, COUNT(*) AS "uses"\n                   FROM commands\n                   WHERE used > (CURRENT_TIMESTAMP - INTERVAL \'1 day\')\n                   GROUP BY command\n                   ORDER BY "uses" DESC\n                   LIMIT 5;\n                '
    records = (await ctx.db.fetch(query))
    value = '\n'.join((f'{lookup[index]}: {command} ({uses} uses)' for (index, (command, uses)) in enumerate(records)))
    e.add_field(name='Top Commands', value=value, inline=False)
    query = 'SELECT guild_id, COUNT(*) AS "uses"\n                   FROM commands\n                   WHERE used > (CURRENT_TIMESTAMP - INTERVAL \'1 day\')\n                   GROUP BY guild_id\n                   ORDER BY "uses" DESC\n                   LIMIT 5;\n                '
    records = (await ctx.db.fetch(query))
    value = []
    for (index, (guild_id, uses)) in enumerate(records):
        if (guild_id is None):
            guild = 'Private Message'
        else:
            guild = self.censor_object((self.bot.get_guild(guild_id) or f'<Unknown {guild_id}>'))
        emoji = lookup[index]
        value.append(f'{emoji}: {guild} ({uses} uses)')
    e.add_field(name='Top Guilds', value='\n'.join(value), inline=False)
    query = 'SELECT author_id, COUNT(*) AS "uses"\n                   FROM commands\n                   WHERE used > (CURRENT_TIMESTAMP - INTERVAL \'1 day\')\n                   GROUP BY author_id\n                   ORDER BY "uses" DESC\n                   LIMIT 5;\n                '
    records = (await ctx.db.fetch(query))
    value = []
    for (index, (author_id, uses)) in enumerate(records):
        user = self.censor_object((self.bot.get_user(author_id) or f'<Unknown {author_id}>'))
        emoji = lookup[index]
        value.append(f'{emoji}: {user} ({uses} uses)')
    e.add_field(name='Top Users', value='\n'.join(value), inline=False)
    (await ctx.send(embed=e))