import datetime
import psutil

import discord
from discord.ext import commands


class Stats:
    """Bot usage statistics."""

    def __init__(self):
        self.process = psutil.Process()
        self.process.cpu_percent()

    @commands.command()
    async def uptime(self, ctx):
        """Tells you how long the bot has been up for."""
        await ctx.send(f'Uptime: {self.get_bot_uptime()}')

    @commands.command(aliases=['stats'])
    async def about(self, ctx):
        """Tells you information about the bot itself."""

        embed = discord.Embed()

        try:
            self.owner
        except AttributeError:
            self.owner = ctx.bot.get_user(140293604726800385)

        embed.set_author(name=str(self.owner), icon_url=self.owner.avatar_url)

        total_members = sum(len(s.members) for s in ctx.bot.guilds)
        unique_members = len(ctx.bot.users)

        voice = 0
        text = 0
        for channel in ctx.bot.get_all_channels():
            if isinstance(channel, discord.TextChannel):
                text += 1
            else:
                voice += 1

        members = f'{total_members} total\n{unique_members} unique'
        embed.add_field(name='Members', value=members)
        embed.add_field(name='Channels', value=f'{text} text\n{voice} voice')
        embed.add_field(name='Uptime', value=self.get_bot_uptime(brief=True))
        embed.set_footer(text='Made with discord.py',
                         icon_url='http://i.imgur.com/5BFecvA.png')
        try:
            embed.timestamp = ctx.bot.uptime
        except AttributeError:
            pass

        embed.add_field(name='Guilds', value=len(ctx.bot.guilds))

        cpu_usage = self.process.cpu_percent()
        memory_usage = self.process.memory_full_info().uss / 2 ** 20
        embed.add_field(name='CPU Usage', value=f'{cpu_usage:.2f}%')
        embed.add_field(name='Memory Usage', value=f'{memory_usage:.2f} MiB')
        await ctx.send(embed=embed)

    def get_bot_uptime(self, *, brief=False):
        now = datetime.datetime.utcnow()
        try:
            delta = now - ctx.bot.uptime
        except AttributeError:
            delta = datetime.timedelta()
        hours, remainder = divmod(int(delta.total_seconds()), 3600)
        minutes, seconds = divmod(remainder, 60)
        days, hours = divmod(hours, 24)

        if not brief:
            if days:
                fmt = '{d} days, {h} hours, {m} minutes, and {s} seconds'
            else:
                fmt = '{h} hours, {m} minutes, and {s} seconds'
        else:
            fmt = '{h}h {m}m {s}s'
            if days:
                fmt = '{d}d ' + fmt

        return fmt.format(d=days, h=hours, m=minutes, s=seconds)


def setup(bot):
    bot.add_cog(Stats())

@@ -389,16 +389,23 @@
 _uptime(
+ctx.bot
 )%7D')%0A%0A  
@@ -563,24 +563,47 @@
 rd.Embed()%0A%0A
+        bot = ctx.bot%0A%0A
         try:
@@ -682,20 +682,16 @@
 owner = 
-ctx.
 bot.get_
@@ -844,28 +844,24 @@
 s) for s in 
-ctx.
 bot.guilds)%0A
@@ -885,28 +885,24 @@
 mbers = len(
-ctx.
 bot.users)%0A%0A
@@ -959,20 +959,16 @@
 nnel in 
-ctx.
 bot.get_
@@ -1379,21 +1379,20 @@
 uptime(b
-rief=
+ot, 
 True))%0A 
@@ -1555,20 +1555,16 @@
 stamp = 
-ctx.
 bot.upti
@@ -1664,20 +1664,16 @@
 lue=len(
-ctx.
 bot.guil
@@ -2007,17 +2007,19 @@
 e(self, 
-*
+bot
 , brief=
@@ -2106,20 +2106,16 @@
 = now - 
-ctx.
 bot.upti

Fix bad reference to ctx