Смотрите, пишу майнркафт экономику в дсе, вот проблема при команде `!mine` алмазы 0, хотя я везде их занес, вообще не понимаю почему и так далее, надеюсь кто-то поможет
Суть чтобы алмазы добывались при железной кирке :)
import discord
from discord.ext import commands
import asyncio
import random
import sqlite3
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
# Создаем подключение к базе данных
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS inventory
(user_id INTEGER PRIMARY KEY, wood INTEGER, coal INTEGER, stone INTEGER, iron INTEGER, tool TEXT, stone_tool TEXT, gold INTEGER)''')
# Проверяем, существует ли столбец diamond
c.execute("PRAGMA table_info(inventory)")
columns = [column[1] for column in c.fetchall()]
if 'diamond' not in columns:
# Добавляем столбец diamond, если его нет
c.execute('''ALTER TABLE inventory ADD COLUMN diamond INTEGER DEFAULT 8''')
# Фиксируем изменения
conn.commit()
@bot.command()
async def mine(ctx):
user = ctx.author
user_id = user.id
c.execute('SELECT * FROM inventory WHERE user_id=?', (user_id,))
user_data = c.fetchone()
if user_data is None:
c.execute('INSERT INTO inventory VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', (user_id, 0, 0, 0, 0, 'Рука', 'Рука', 0, 8))
conn.commit()
user_data = (user_id, 0, 0, 0, 0, 'Рука', 'Рука', 0, 0)
wood_count = random.randint(1, 20)
if user_data[5] == 'Рука':
coal_count = 0
stone_count = 0
iron_count = 0
gold_count = 0
diamond_count = 0
elif user_data[5] == '<:2465stonepickaxe:1159001582495596594>':
coal_count = random.randint(1, 20)
stone_count = random.randint(1, 20)
iron_count = random.randint(1, 10)
gold_count = 0
diamond_count = 0
elif user_data[5] == '<:939223290105454632:1164940159050059786>':
coal_count = random.randint(1, 20)
stone_count = random.randint(1, 20)
iron_count = random.randint(1, 10)
gold_count = random.randint(1, 5)
diamond_count = 0
elif user_data[5] == '<:939195860317773856:1164153649296048148>':
coal_count = random.randint(1, 20)
stone_count = random.randint(1, 20)
iron_count = random.randint(1, 10)
gold_count = 0
diamond_count = random.randint(1, 3)
elif user_data[5] == '<:939223290105454632:1164940159050059786>': # Добавлено условие для железной кирки
coal_count = random.randint(1, 20)
stone_count = random.randint(1, 20)
iron_count = random.randint(1, 10)
gold_count = random.randint(1, 5)
diamond_count = random.randint(1, 2) # Добавлено добычу алмазов при использовании железной кирки
else:
coal_count = 0
stone_count = 0
iron_count = 0
gold_count = 0
diamond_count = 0
# Additional mining with wooden pickaxe
if user_data[5] == '<:939195859801870387:1164139341979860992>':
coal_count += random.randint(1, 5)
stone_count += random.randint(1, 10)
new_wood_count = user_data[1] + wood_count
new_coal_count = user_data[2] + coal_count
new_stone_count = user_data[3] + stone_count
new_iron_count = user_data[4] + iron_count
new_gold_count = user_data[7] + gold_count
new_diamond_count = user_data[8] + diamond_count
c.execute('UPDATE inventory SET wood=?, coal=?, stone=?, iron=?, gold=?, diamond=? WHERE user_id=?',
(new_wood_count, new_coal_count, new_stone_count, new_iron_count, new_gold_count, new_diamond_count, user_id))
conn.commit()
print(f"Инструмент пользователя: {user_data[5]}")
print(f"Добыча алмазов: {diamond_count}")
user_tag = f"{user.name}#{user.discriminator}"
embed = discord.Embed(title="Копаем...", color=0x5865F2)
embed.set_author(name=user_tag)
embed.add_field(
name="**Вы накопали:**",
value=f"{wood_count} <:939195860422623252:1164153659861499984>",
inline=True
)
embed.add_field(
name="**Дополнительная добыча:**",
value=f"{coal_count} <:939195859894169600:1164137979149819955>\n"
f"{stone_count} <:939195860456210502:1164137958903922698>\n"
f"{iron_count} <:939195860317773856:1164153649296048148>\n"
f"{gold_count} <:939195860129042452:1164153647010160660>\n"
f"{diamond_count} <:939195860389081119:1164153645365993472>",
inline=True
)
embed.add_field(name="**Инструмент:**", value=user_data[5], inline=True)
images = [
"https://cdn.discordapp.com/attachments/1132947392384221275/1164444458587271238/new1.png?ex=65433c69&is=6530c769&hm=18aeb0130bf40d9adc8363e8693a75e4d84b27b9326ecfcfd889ac7ed42c7885&",
"https://cdn.discordapp.com/attachments/1132947392384221275/1164444482851311646/new2_1.png?ex=65433c6f&is=6530c76f&hm=7a9d45a66353ec87522056184dc4ad5e757c08b6c188da42c28ddd19eb6d02ce&",
"https://cdn.discordapp.com/attachments/1132947392384221275/1164444546432778310/new3_1.png?ex=65433c7e&is=6530c77e&hm=b8e81d0c0bcf11fcab1ebbdb0d249b8008ecb787914779006e26dda9d371396f&"
]
msg = await ctx.send(embed=embed)
for i, image_url in enumerate(images, start=1):
await asyncio.sleep(2)
embed = discord.Embed(title="Копаем...", color=0x5865F2)
embed.set_author(name=user_tag)
embed.add_field(
name="**Вы накопали:**",
value=f"{wood_count} <:939195860422623252:1164153659861499984>",
inline=True
)
embed.add_field(
name="**Дополнительная добыча:**",
value=f"{coal_count} <:939195859894169600:1164137979149819955>\n"
f"{stone_count} <:939195860456210502:1164137958903922698>\n"
f"{iron_count} <:939195860317773856:1164153649296048148>\n"
f"{gold_count} <:939195860129042452:1164153647010160660>\n"
f"{diamond_count} <:939195860389081119:1164153645365993472>",
inline=True
)
embed.add_field(name="**Инструмент:**", value=user_data[5], inline=True)
embed.set_image(url=image_url)
msg = await msg.edit(embed=embed)
if i == 1:
await asyncio.sleep(2)
elif i == 2:
await asyncio.sleep(2)