Использую Disnake, Pillow и sqlite3
Мой код:
async def profile(self, ctx, member: disnake.Member = None):
await ctx.response.defer()
if not member:
member = ctx.author
scopes = 0
try:
scopes = Memory.read(f"scope/{member.id}balls.txt")
except:
scopes = 0
balance = 0
users = None
with sqlite3.connect("database.db") as db:
cursor = db.cursor()
for guild, user, bal in cursor.execute("SELECT * FROM balances"):
if guild == ctx.guild.id:
if user == member.id:
users = user
balance = bal
if not users:
with sqlite3.connect("database.db") as db:
cursor = db.cursor()
cursor.execute("INSERT INTO balances VALUES(?, ?, ?)", (ctx.guild.id, member.id, 0))
balance = 0
if not balance:
balance = 0
t = member.status
if t == disnake.Status.online:
d = " В сети"
t = member.status
if t == disnake.Status.offline:
d = "⚪ Не в сети"
t = member.status
if t == disnake.Status.idle:
d = " Не активен"
t = member.status
if t == disnake.Status.dnd:
d = " Не беспокоить"
img = Image.new('RGBA', (500, 150), '#000000')
backgr = ["https://cdn.glitch.global/5fcfa7e8-8436-4acd-a852-e721cd1b531e/1614397342_47-p-temnii-multyashnii-fon-64.png?v=1670188383348","https://cdn.glitch.global/5fcfa7e8-8436-4acd-a852-e721cd1b531e/1622768497_26-phonoteka_org-p-noch-art-minimalizm-krasivo-28.png?v=1670188403979","https://cdn.glitch.global/5fcfa7e8-8436-4acd-a852-e721cd1b531e/i.png?v=1670188415480"]
r = requests.get(random.choice(backgr), stream = True)
r = Image.open(io.BytesIO(r.content))
r = r.convert("RGBA")
img.paste(r, (0, 0, 500, 150))
url = str(member.avatar.url)
r = requests.get(url, stream = True)
r = Image.open(io.BytesIO(r.content))
r = r.convert('RGBA')
r = r.resize((100, 100))
img.paste(r, (15, 15, 115, 115))
idraw = ImageDraw.Draw(img)
name = member.name
headline = ImageFont.truetype('comfortaa.ttf', size = 25)
undertext = ImageFont.truetype('comfortaa.ttf', size = 13)
idraw.text((125, 15), f'{name}', font=headline, fill="#ffffff")
idraw.text((125, 50), f'#{member.discriminator}', font=undertext, fill="#ffffff")
idraw.text((125, 70), f'ID: \n{member.id}', font = undertext, fill="#ffffff")
idraw.text((125, 110), f'Статус: {d}', font = undertext, fill="#ffffff")
idraw.text((125, 130), f"Кол-во очков: {scopes}", font = undertext, fill="#ffffff")
idraw.text((125, 150), f"Баланс: {int(balance)}")
idraw.text((10, 155), f'{self.bot.user.name} Draw\'s', font=undertext, fill="#ffffff")
img.save('user_card.png')
await ctx.send(file=disnake.File("user_card.png"))
Но при его запуске выдаёт ошибку:
Command raised an exception: UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-5: ordinal not in range(256)
Что я заметил, если закоментировать строку
idraw.text((125, 150), f"Баланс: {int(balance)}")
То всё сразу работает
Как исправить это? В интернете нашёл только что делать если такое с внесением данных в таблицу