взял слитый бот для стаффа в дискорде,
ошибка - disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'NoneType' object is not subscriptable
код (весь не влазит)
import disnake
from disnake.ext import commands
import sqlite3
from PIL import Image, ImageDraw, ImageFont
from config import *
import requests
from io import BytesIO
import asyncio
class profile(commands.Cog):
def __init__(self, client):
self.client = client
@commands.slash_command(name="staff")
async def staff(self, inter):
pass
@staff.sub_command(
name='profile',
description='Посмотреть стафф профиль'
)
async def profile(self, inter, пользователь: disnake.Member = None):
if пользователь == None:
пользователь = inter.user
global user
user = пользователь
if STAFF_ROLE in [role.id for role in пользователь.roles]:
await inter.response.defer()
conn = sqlite3.connect('main.db')
cursor = conn.cursor()
font_o = ImageFont.truetype("assets/name.ttf", size=25)
font_s = ImageFont.truetype("assets/status.ttf", size=35)
if пользователь.avatar is None:
url1 = Q_IMAGE
else:
url1 = пользователь.avatar.url
response = requests.get(url1)
avatar = Image.open(BytesIO(response.content))
avatar = avatar.resize((225, 225), Image.Resampling.LANCZOS)
mask = Image.new("L", avatar.size, 0)
draw_mask = ImageDraw.Draw(mask)
draw_mask.ellipse((0, 0, 225, 225), fill=255)
user_card = Image.open('assets/profile.png')
cursor.execute("SELECT points FROM users WHERE user_id = ?", (пользователь.id,))
result = cursor.fetchone()
points = result[0]
cursor.execute("SELECT warn FROM users WHERE user_id = ?", (пользователь.id,))
result2 = cursor.fetchone()
warns = result2[0]
cursor.execute("SELECT time FROM users WHERE user_id = ?", (пользователь.id,))
result3 = cursor.fetchone()
online = result3[0]
cursor.execute("SELECT otpysk FROM users WHERE user_id = ?", (пользователь.id,))
result4 = cursor.fetchone()
otpysk = result4[0]
cursor.execute("SELECT role FROM users WHERE user_id = ?", (пользователь.id,))
result5 = cursor.fetchone()
rab = result5[0]
minutes = int(online % 60)
hour = int(online // 60)
if hour < 1:
hour = 0
if minutes < 1 or minutes >= 60:
minutes = 0
maxx = PRED
idraw = ImageDraw.Draw(user_card)
idraw.text((130, 200), str(f'{hour}ч. {minutes}м.'), (255, 255, 255), font=font_o)
idraw.text((670, 200), str(points), (255, 255, 255), font=font_o)
idraw.text((620, 320), str(f'{warns} из {maxx}'), (255, 255, 255), font=font_o)
idraw.text((350, 460), str(f'{rab}'), (255, 255, 255), font=font_o)
if otpysk > 0:
idraw.text((130, 320), str(f'ещё {otpysk} дней'), (255, 255, 255), font=font_o)
else:
idraw.text((130, 320), str(f'Не в отпуске'), (255, 255, 255), font=font_o)
user_card.paste(avatar, (317, 112), mask)
user_card.save('assets/profile_file.png', quality=95)
file = disnake.File("assets/profile_file.png", filename="profile.png")
view = disnake.ui.View()
if CURATOR in [role.id for role in inter.user.roles] or \
ADMIN in [role.id for role in inter.user.roles]:
view.add_item(disnake.ui.Button(label="Выдать поинты", style=disnake.ButtonStyle.gray, custom_id="points"))
else:
view.add_item(disnake.ui.Button(label="Выдать поинты", style=disnake.ButtonStyle.gray, custom_id="points", disabled=True))
if CURATOR in [role.id for role in inter.user.roles] or \
ADMIN in [role.id for role in inter.user.roles]:
view.add_item(disnake.ui.Button(label="Забрать поинты", style=disnake.ButtonStyle.gray, custom_id="upoints"))
else:
view.add_item(disnake.ui.Button(label="Забрать поинты", style=disnake.ButtonStyle.gray, custom_id="upoints", disabled=True))
if пользователь.id == inter.user.id:
view.add_item(disnake.ui.Button(label="Взять отпуск", style=disnake.ButtonStyle.gray, custom_id="otpesk"))
else:
view.add_item(disnake.ui.Button(label="Взять отпуск", style=disnake.ButtonStyle.gray, custom_id="otpesk", disabled=True))
view.add_item(disnake.ui.Button(label="Выйти", style=disnake.ButtonStyle.red, custom_id="back"))
await inter.send(file=file, view=view)
else:
embed = disnake.Embed(description="Пользователь **не является** участником стаффа", color=0x2b2d31)
if пользователь.avatar is None:
embed.set_thumbnail(url=Q_IMAGE)
else:
embed.set_thumbnail(url=пользователь.avatar.url)
embed.set_author(name="Ой, ошибка", icon_url=f"{IMAGE}")
await inter.send(embed=embed, ephemeral=True)
conn.commit()
conn.close()
@staff.sub_command(name="top", description="Топ-10 по поинтам")
async def top(self, inter):
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
pointss = self.client.get_emoji(POINTSS)
cursor.execute("SELECT user_id, points FROM users ORDER BY points DESC LIMIT 10")
top_users = cursor.fetchall()
embed = disnake.Embed(title="Топ-10 участников по поинтам", color=0x2b2d31)
if top_users:
for index, (user_id, points) in enumerate(top_users[:3], start=1):
user = self.client.get_user(user_id)
embed.add_field(name=f"{index}. {user.name}", value=f"{points} {pointss}", inline=True)
if len(top_users) > 3:
other_users_info = "\n".join([f"{index+3}. {self.client.get_user(user_id).name} - {points} {pointss}" for index, (user_id, points) in enumerate(top_users[3:], start=3)])
embed.add_field(name="Остальные места", value=other_users_info, inline=True)
embed.set_thumbnail(url=inter.guild.icon.url)
else:
embed.add_field(name="Нет данных", value="Нет данных для отображения топ-10.", inline=True)
embed.set_thumbnail(url=inter.guild.icon.url)
conn.commit()
conn.close()
await inter.send(embed=embed)
@commands.Cog.listener()
async def on_button_click(self, inter: disnake.MessageInteraction):
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
otp = disnake.utils.get(inter.guild.roles, id = OTPYSK)
if inter.data.custom_id == "back":
await inter.message.delete()
if inter.data.custom_id == "otpesk":
embed = disnake.Embed(description="Выберите, на какой **срок** вы хотите **взять** отпуск", color=0x2b2d31)
if user.avatar is None:
embed.set_thumbnail(url=Q_IMAGE)
else:
embed.set_thumbnail(url=user.avatar.url)
embed.set_author(name="Отпуск", icon_url=f"{IMAGE}")
embed.set_footer(text="Цена 1 дня отпуска - 100 поинтов!")
view = disnake.ui.View()
cursor.execute("SELECT points FROM users WHERE user_id = ?", (user.id,))
result3 = cursor.fetchone()
points = result3[0]
if points >= 100:
view.add_item(disnake.ui.Button(label="1 день", style=disnake.ButtonStyle.gray, custom_id="one"))
else:
view.add_item(disnake.ui.Button(label="1 день", style=disnake.ButtonStyle.gray, custom_id="one", disabled=True))
if points >= 200:
view.add_item(disnake.ui.Button(label="2 дня", style=disnake.ButtonStyle.gray, custom_id="two"))
else:
view.add_item(disnake.ui.Button(label="2 дня", style=disnake.ButtonStyle.gray, custom_id="two", disabled=True))
if points >= 300:
view.add_item(disnake.ui.Button(label="3 дня", style=disnake.ButtonStyle.gray, custom_id="tre"))
else:
view.add_item(disnake.ui.Button(label="3 дня", style=disnake.ButtonStyle.gray, custom_id="tre", disabled=True))
if points >= 700:
view.add_item(disnake.ui.Button(label="7 дней", style=disnake.ButtonStyle.gray, custom_id="week"))
else:
view.add_item(disnake.ui.Button(label="7 дней", style=disnake.ButtonStyle.gray, custom_id="week", disabled=True))
view.add_item(disnake.ui.Button(label="Выйти", style=disnake.ButtonStyle.red, custom_id="back"))
await inter.send(embed=embed, view=view)
conn.commit()