Как взять картинку из сообщения и отправить её?

Хочу сделать что-то по типу сшакаливания картинки в Discord.Py, но у меня чуточку не получается.

Вот код:

@commands.command()
    async def шакал(self, ctx):
        if len(ctx.message.attachments) > 0:
            img = ctx.message.attachments[0].url
            img.save('example.png')
            await ctx.send(file=discord.File('example.png'))
            os.remove('example.png')
        else:
            await ctx.send('даун картинку добавь')

А так-же ошибка:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'save'

(заранее попрошу не бить за код, я особо не шарю в PIL)


Ответы (1 шт):

Автор решения: RAINGM

Как насчёт библиотеки Pillow?

import requests
from PIL import Image

@commands.command()
    async def шакал(self, ctx):
        if len(ctx.message.attachments) > 0:
            img = Image.open(requests.get(ctx.message.attachments[0].url, stream=True).raw)
            img.save('example.png')
            await ctx.send(file=discord.File('example.png'))
            os.remove('example.png')
        else:
            await ctx.send('даун картинку добавь')
→ Ссылка