Ошибка связанная io и PIL в python, пытался написать бота
Учился писать ботов у одного ютубера, переписал весь его код, но почему то у меня этот бот выдает ошибки:
Ignoring exception in command card_user:
Traceback (most recent call last):
File "C:\Users\marse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\marse\OneDrive\Рабочий стол\MarsBot\4E.py", line 50, in card_user
response = Image.open(io.BytesIO(response.content))
File "C:\Users\marse\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py", line 2958, in open
raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000002386E86F8B0>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\marse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\marse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\marse\AppData\Local\Programs\Python\Python39\lib\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: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000002386E86F8B0>
Вот мой код:
import discord
from PIL import Image,ImageDraw,ImageFont
from discord.ext import commands
from discord import Intents
import os
from time import sleep
import requests
from PIL import Image, ImageFont, ImageDraw
import io
import asyncio
@bot.command(aliases = ['card','profile'])
async def card_user(ctx):
await ctx.channel.purge(limit=1)
img = Image.new('RGBA', (400, 200), '#232529')
url = str(ctx.author.avatar_url)[:-10]
response = requests.get(url, stream=True)
response = Image.open(io.BytesIO(response.content))
response = response.convert('RGBA')
response = response.resize((100, 100), Image.ANTIALIAS)
img.paste(response, (15, 15, 115, 115))
idraw = ImageDraw.Draw(img)
name = ctx.author.name
tag = ctx.author.discriminator
headline = ImageFont.truetype('arial.ttf', size=20)
undertext = ImageFont.truetype('arial.ttf', size=12)
idraw.text((145, 15), f'{name}#{tag}', font=headline)
idraw.text((145, 50), f'ID: {ctx.author.id}', font=undertext)
img.save('user_card.png')
await ctx.send(file=discord.File(fp='user_card.png'))