在“反转”命令中获取错误discord.py重写v1.3.4

时间:2020-08-07 12:55:32

标签: python-3.x python-imaging-library discord discord.py discord.py-rewrite

这是我的代码-

@client.command()
async def invert(ctx, user: discord.User = None):
    async with aiohttp.ClientSession() as session:
        async with session.get(str(user.avatar_url)) as response:
            image_bytes = await response.read()

    img = Image.open(image_bytes)
    await ImageOps.invert(img)

    with io.BytesIO() as my_image:
        img.save(my_image,
                 'PNG')
        my_image.seek(0)
        await ctx.send(file=discord.File(fp=my_image,
                                         filename="image.png"))

它给出了错误-

Traceback (most recent call last):
  File "C:\Users\k\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\k\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\k\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 6: invalid continuation byte

我以前从未使用过PIL,因此会有所帮助。

1 个答案:

答案 0 :(得分:0)

尝试以这种方式转换图像:

private void CardView_OnShowMore(object sender, EventArgs e)
    {
        var product = (sender as CardView)?.ShowMoreCommandParameter as Product;
        Navigation.PushModalAsync(new ProductDetailPage(new Product()
        {
            Title = product.Title,
            Amount = product.Amount,
            Description = product.Description,
            ImageProfile = product.ImageProfile,
            Images = product.Images,
            Location = product.Location,
            RegistrationDate = product.RegistrationDate,
            _id = product._id
        }), true);
    }