import io

import aiohttp
from discord.ext import commands
import yaml


class Cat:
    def __init__(self, bot):
        self.bot = bot
        with open('config.yaml') as file:
            data = yaml.load(file)
        self.key = data.get('cat_key', '')
        self.url = 'http://thecatapi.com/api/images/get'
        self.params = {'api_key': self.key,
                       'type': 'png,jpg'}

    @commands.command()
    async def cat(self, ctx):
        s = self.bot.session
        async with ctx.typing(), s.get(self.url, params=self.params) as resp:
            image = io.BytesIO(await resp.content.read())
            ext = resp.headers['Content-Type'].partition('/')[2]
        await ctx.send(file=image, filename=f'{ctx.message.id}.{ext}')


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

import io

import aiohttp
import discord
from discord.ext import commands
from lxml import etree
import yaml


class Cat:
    def __init__(self, bot):
        self.bot = bot
        with open('config.yaml') as file:
            data = yaml.load(file)
        self.key = data.get('cat_key', '')
        self.url = 'http://thecatapi.com/api/images/get'
        self.params = {'api_key': self.key,
                       'type': 'png,jpg',
                       'format': 'xml',
                       }

    @commands.command()
    async def cat(self, ctx):
        session = self.bot.session
        async with ctx.typing():
            async with session.get(self.url, params=self.params) as resp:
                root = etree.fromstring(await resp.text())
            url = root.find('.//url').text
            embed = discord.Embed()
            embed.set_image(url=url)
        await ctx.send(embed=embed)



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

Send image in embed because aiohttp doesn't know how to parse links
Send image in embed because aiohttp doesn't know how to parse links

  import io
  
  import aiohttp
+ import discord
  from discord.ext import commands
+ from lxml import etree
  import yaml
  
  
  class Cat:
      def __init__(self, bot):
          self.bot = bot
          with open('config.yaml') as file:
              data = yaml.load(file)
          self.key = data.get('cat_key', '')
          self.url = 'http://thecatapi.com/api/images/get'
          self.params = {'api_key': self.key,
-                        'type': 'png,jpg'}
+                        'type': 'png,jpg',
+                        'format': 'xml',
+                        }
  
      @commands.command()
      async def cat(self, ctx):
-         s = self.bot.session
+         session = self.bot.session
+         async with ctx.typing():
-         async with ctx.typing(), s.get(self.url, params=self.params) as resp:
+             async with session.get(self.url, params=self.params) as resp:
-             image = io.BytesIO(await resp.content.read())
-             ext = resp.headers['Content-Type'].partition('/')[2]
-         await ctx.send(file=image, filename=f'{ctx.message.id}.{ext}')
+                 root = etree.fromstring(await resp.text())
+             url = root.find('.//url').text
+             embed = discord.Embed()
+             embed.set_image(url=url)
+         await ctx.send(embed=embed)
+ 
  
  
  def setup(bot):
      bot.add_cog(Cat(bot))
  
Send image in embed because aiohttp doesn't know how to parse links
## Code Before:
import io

import aiohttp
from discord.ext import commands
import yaml


class Cat:
    def __init__(self, bot):
        self.bot = bot
        with open('config.yaml') as file:
            data = yaml.load(file)
        self.key = data.get('cat_key', '')
        self.url = 'http://thecatapi.com/api/images/get'
        self.params = {'api_key': self.key,
                       'type': 'png,jpg'}

    @commands.command()
    async def cat(self, ctx):
        s = self.bot.session
        async with ctx.typing(), s.get(self.url, params=self.params) as resp:
            image = io.BytesIO(await resp.content.read())
            ext = resp.headers['Content-Type'].partition('/')[2]
        await ctx.send(file=image, filename=f'{ctx.message.id}.{ext}')


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

## Instruction:
Send image in embed because aiohttp doesn't know how to parse links
## Code After:
import io

import aiohttp
import discord
from discord.ext import commands
from lxml import etree
import yaml


class Cat:
    def __init__(self, bot):
        self.bot = bot
        with open('config.yaml') as file:
            data = yaml.load(file)
        self.key = data.get('cat_key', '')
        self.url = 'http://thecatapi.com/api/images/get'
        self.params = {'api_key': self.key,
                       'type': 'png,jpg',
                       'format': 'xml',
                       }

    @commands.command()
    async def cat(self, ctx):
        session = self.bot.session
        async with ctx.typing():
            async with session.get(self.url, params=self.params) as resp:
                root = etree.fromstring(await resp.text())
            url = root.find('.//url').text
            embed = discord.Embed()
            embed.set_image(url=url)
        await ctx.send(embed=embed)



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