discord бота для сервера. В нём присутствует экономика:
conn = sqlite3.connect("datebase.db")
cursor = conn.cursor()
print('work')
#Ивенты
@bot.event
async def on_member_join(member):
cursor.execute(f"SELECT id FROM users where id={member.id}")
if cursor.fetchone()==None:
cursor.execute(f"INSERT INTO users VALUES ({member.id}, '{member.name}', '<@{member.id}>', 0, 'S','[]',0,0)")
else:
pass
conn.commit()
@bot.event
async def on_message(message):
if len(message.content) >= 5:
for row in cursor.execute(f"SELECT xp,lvl,money FROM users where id={message.author.id}"):
expi=row[1]+random.randint(1, 10)
cursor.execute(f'UPDATE users SET xp={expi} where id={message.author.id}')
lvch=expi/(row[0]*1000)
print(int(lvch))
lv=int(lvch)
if row[1] < lv:
await message.channel.send(f'Новый уровень!')
bal=1000*lv
cursor.execute(f'UPDATE users SET lvl={lv},money={bal} where id={message.author.id}')
await bot.process_commands(message)
conn.commit()
#Команды
@bot.slash_command()
async def profile(inter):
for row in cursor.execute(f"SELECT nickname,money,lvl,xp FROM users where id={inter.author.id}"):
embed = disnake.Embed(
title=f'Профиль пользователя {inter.author}',
color= 0x27db63
)
embed.set_author(
name=f"{inter.author}",
icon_url=f"{inter.author.avatar}"
)
embed.set_image(file=disnake.File("photo/mythicalworld.png"))
embed.add_field(name="Ник: ", value=f"{row[0]}", inline=False)
embed.add_field(name="Баланс:", value=f"{row[1]}", inline=False)
embed.add_field(name="Уровень", value=f"{row[2]}", inline=False)
embed.add_field(name="Опыт", value=f"{row[3]}", inline=False)
await inter.response.send_message(embed=embed)
@bot.slash_command()
async def inventory(inter):
counter=0
for row in cursor.execute(f"SELECT inventory FROM users where id={inter.author.id}"):
data=json.loads(row[0])
for row in data:
prt=row
for row in cursor.execute(f"SELECT id,type,name FROM shop where id={prt}"):
counter+=1
embed = disnake.Embed(
title=f'Профиль пользователя {inter.author}',
color= 0x27db63
)
embed.set_author(
name=f"{inter.author}",
icon_url=f"{inter.author.avatar}"
)
embed.set_image(file=disnake.File("photo/mythicalworld.png"))
embed.add_field(name="Ник: ", value=f"{row[0]}", inline=False)
embed.add_field(name="Баланс:", value=f"{row[1]}", inline=False)
embed.add_field(name="Уровень", value=f"{row[2]}", inline=False)
if counter==len(data):
await inter.send(embed=embed)
@bot.slash_command()
async def shop(inter):
counter=0
table=[["id","type","name","cost"]]
for row in cursor.execute(f"SELECT id,type,name,cost FROM shop"):
counter+=1
table.append([row[0],row[1],row[2],row[3]])
if counter==4:
await inter.send(f'>\n{(table)}')
async def buy(inter, a: int):
uid=inter.author.id
await inter.send('Обработка... Если ответа не последует, указан неверный id предмета [buy {id}]')
for row in cursor.execute(f"SELECT money FROM users where id={uid}"):
money = row[0]
for row in cursor.execute(f"SELECT id,name,cost FROM shop where id={a}"):
cost=row[2]
if money >= cost:
money -=cost
await inter.send(f'Вы приобрели "{row[1]}" за {row[2]}')
for row in cursor.execute(f"SELECT inventory FROM users where id={uid}"):
data=json.loads(row[0])
data.append(a)
daed=json.dumps(data)
cursor.execute('UPDATE users SET money=?,inventory = ? where id=?',(money,daed,uid))
pass
if money < cost:
await inter.send(f'Недостаточно средств')
pass
conn.commit()
Дискорд выдаёт ошибки на команды shop, inventory, но при этом ошибок в консоли нет.