@AdvoKappa

Почему две команды if сравнения совмещаются?

@bot.command()
async def M1(message):
    with open('coins.json', 'r') as f:
        users = json.load(f)

    await update_data(users, message.author)
    await start(users, message.author, message)

async def start(users, user, message):
    if users[str(user.id)]['coins'] > 3065000:
        await update_data(users, message.author)
        await delete_coins(users, message.author, 3065000)        
        await send(message)
    else:
        await message.channel.send('Недостаточно средств для покупки.')

    with open('coins.json','w') as f:
        json.dump(users, f)

async def update_data(users, user):
    if not str(user.id) in users:
        users[str(user.id)] = {}
        users[str(user.id)]['coins'] = 0

async def delete_coins(users, user, coin):
    users[str(user.id)]['coins'] -= coin

async def send(message):
    await message.channel.send(f'Да')  

@bot.command()
async def M2(message):
    with open('coins.json', 'r') as f:
        users = json.load(f)

    await update_data(users, message.author)
    await start(users, message.author, message)

async def start(users, user, message):
    if users[str(user.id)]['coins'] > 2065000:
        await update_data(users, message.author)
        await delete_coins(users, message.author, 2065000)        
        await send(message)
    else:
        await message.channel.send('Недостаточно средств для покупки')

    with open('coins.json','w') as f:
        json.dump(users, f)

async def update_data(users, user):
    if not str(user.id) in users:
        users[str(user.id)] = {}
        users[str(user.id)]['coins'] = 0

async def delete_coins(users, user, coin):
    users[str(user.id)]['coins'] -= coin

async def send(message):
    await message.channel.send(f'Да2')


Отдельно команды работают правильно, но если их поместить в один код - то команда M1 будет выдавать значения команды M2, а именно вычитать число 2065000 и Да2, при команде M2 выдаёт всё из команды M2. Почему так?
  • Вопрос задан
  • 100 просмотров
Решения вопроса 1
SoreMix
@SoreMix Куратор тега Python
yellow
Вас не смущает, что у вас функции просто дублируются? Линтер не подсвечивает?
У вас две функции старт, два апдейт дата и тд
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы