S
S
Soneiko2020-06-01 13:00:40
Python
Soneiko, 2020-06-01 13:00:40

Pillow not working?

async def check_lvl(self, x,y,z,c):
        cursor.execute("SELECT lvl FROM users WHERE user_id=? AND guild_id=?", [(y), (x)])
        user_lvl = cursor.fetchone()
        lvl = 15**(1.5+(user_lvl[0]*0.2))
        cursor.execute("SELECT exp FROM users WHERE user_id=? AND guild_id=?", [(y), (x)])
        user_xp = cursor.fetchone()
        avatarstr = str(z)[:-10]
        if user_xp[0] >= lvl:
            newLvl = user_lvl[0] + 1
            print(newLvl)
            cursor.execute("UPDATE users SET lvl = ? WHERE user_id=? AND guild_id=?", [(newLvl), (y), (x)])
            conn.commit()
            lvl_crop = Image.open("croplvl.png")
            response = requests.get(avatarstr)
            response = Image.open(io.BytesIO(response.content))
            response = response.convert("RGBA")
            response = response.resize((140, 140), Image.ANTIALIAS)

            lvl_crop.paste(response, (30,10))
            idraw = ImageDraw.Draw(lvl_crop)
            text = "Level up!"
            text1 = f"Lvl {newLvl}"
            font1 = ImageFont.truetype("6500.ttf", size=20)
            font2 = ImageFont.truetype("6500.ttf", size=24)
            idraw.text((60, 155), text, font=font1)
            idraw.text((70, 180), text1, font=font2)

            lvl_crop.save('lvl_send.jpg')
            log = self.atos.get_channel(703670901052276777)
            await log.send(f" | {c} leveled up!")
            await log.send(file = discord.File(fp = "lvl_send.jpg"))

@commands.Cog.listener()
    async def on_message(self, message):
        if message.author.id == self.atos.user.id:
            return
        else:
            if message.content.startswith("!"):
                pass
            else:
                avatar = message.author.avatar_url
                user_name = message.author.name
                user_id = str(message.author.id)
                guild_id = str(message.guild.id)
                if not self.check_account(guild_id, user_id):
                    self.create_account(guild_id, user_id)
                else:
                    self.add_xp(guild_id, user_id)
                    await self.check_lvl(guild_id, user_id, avatar, user_name)

When I write a message, then when I increase the level, it sends a message normally. But if others have an increase, then a mistake.
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\User\Desktop\ATOS\Cogs\level.py", line 103, in on_message
    await self.check_lvl(guild_id, user_id, avatar, user_name)
  File "c:\Users\User\Desktop\ATOS\Cogs\level.py", line 69, in check_lvl
    response = Image.open(io.BytesIO(response.content))
  File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PIL\Image.py", line 2895, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x073B8708>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question