A
A
AdvoKappa2020-11-14 23:28:22
Python
AdvoKappa, 2020-11-14 23:28:22

Why do two if comparison statements overlap?

@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')


Separately, the commands work correctly, but if they are placed in one code, then the M1 command will issue the values ​​of the M2 command, namely, subtract the number 2065000 and Yes2, with the M2 command it will return everything from the M2 command. Why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-11-15
@AdvoKappa

Doesn't it bother you that your functions are simply duplicated? Linter not highlighting?
You have two start functions, two update date, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question