Home>

I need to make the bot "pixelate" the avatar of the mentioned person. Here is my code:

@bot.command()
async def pixelate(ctx, user: discord.Member):
    response= requests.get('https://some-random-api.ml/canvas/pixelate')
    json_data= json.loads(response.text)
    embed= discord.Embed(color= 0xff9900, title= 'Pixeling')
    embed.set_image(url= json_data['avatar'])
    await ctx.send(embed= embed)

But here's the problem: when I go to this site, it gives me this:

error "Missing avatar queries"

If I leave the code as I wrote above, then when I use the command, I get this:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'avatar'

And here is the question: how to install this avatar?

  • Answer # 1

    The link itself that you provided ( https://some-random-api.ml/canvas/pixelate)is the URL to make an API request to the server. The address is not intended to view content through some kind of GUI and expects you to provide some kind of input on the login.

    In this case, the server returned an error because it did not receive an image to process.


    In the documentation of this service, there is 90% , written immediately inPythonfor the librarydiscord-py. Searching for instructions or immediately ready-made solutions is the first thing you had to do when solving this problem.

    After working with the service, all that remains to be done is to replace the API request address from the example with pixelating the image:

    @bot.command()
    async def pixelate(ctx, user: discord.Member=None):
        if not user:
            user= ctx.author
        async with aiohttp.ClientSession() as session:
            async with session.get(f'https://some-random-api.ml/canvas/pixelate?avatar={user.avatar_url_as(format="png", size=1024)}') as trigImg:
                await session.close()
                embed= discord.Embed(color= 0xff9900, title= 'Pixeling')
                embed.set_image(url= trigImg.url)
                await ctx.send(embed= embed)
    
  • Answer # 2

    The link itself that you provided ( https://some-random-api.ml/canvas/pixelate)is the URL to make an API request to the server. The address is not intended to view content through some kind of GUI and expects you to provide some kind of input on the login.

    In this case, the server returned an error because it did not receive an image to process.


    In the documentation of this service, there is 90% , written immediately inPythonfor the librarydiscord-py. Searching for instructions or immediately ready-made solutions is the first thing you had to do when solving this problem.

    After working with the service, all that remains to be done is to replace the API request address from the example with pixelating the image:

    @bot.command()
    async def pixelate(ctx, user: discord.Member=None):
        if not user:
            user= ctx.author
        async with aiohttp.ClientSession() as session:
            async with session.get(f'https://some-random-api.ml/canvas/pixelate?avatar={user.avatar_url_as(format="png", size=1024)}') as trigImg:
                await session.close()
                embed= discord.Embed(color= 0xff9900, title= 'Pixeling')
                embed.set_image(url= trigImg.url)
                await ctx.send(embed= embed)