SHARE
TWEET

Untitled

a guest Sep 11th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import telebot
  2. from telebot import TeleBot
  3. import json
  4. bot = telebot.TeleBot('897115094:AAH4UWOsIQHNSBTPHUxSyJPnloIWlcgхххх')
  5.  
  6. @bot.message_handler(content_types=['text'])
  7. def shoto(message):
  8.  id = message.from_user.id
  9.  button_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back')
  10.  keyboard_back = types.InlineKeyboardMarkup()
  11.  keyboard_back.add(button_back)
  12.  with open('promos.json', 'r') as f:
  13.   a = json.load(f)['promo1']
  14.  if message.text == a:
  15.   with open('bal.json', 'r') as bal:
  16.    balans = json.load(bal)['bal'+str(id)]
  17.   with open('bal.json', 'r') as bal:
  18.    json_data = json.load(bal)
  19.    json_data['bal'+str(id)] = str(balans + 100)
  20.   with open('bal.json', 'w') as d:
  21.    d.write(json.dumps(json_data))
  22.   with open('bal.json', 'r') as bal:
  23.    print(bal.read())
  24.    #выводит {"bal730888010": "100"}
  25.  
  26. @bot.callback_query_handler(func=lambda call:call.data in [ 'bal'])   def asd(call):
  27.    if call.data == 'bal':
  28.     id = call.message.from_user.id#пробывал вручную подставлять id, результат тот же
  29.    button_back = types.InlineKeyboardButton(text = 'Назад', callback_data = 'back1')
  30.    keyboard_back = types.InlineKeyboardMarkup()
  31.    keyboard_back.add(button_back)
  32.    with open('bal.json', 'r') as bala:
  33.     da_zapustis_ty=json.load(bala)['bal'+id]
  34.    print(da_zapustis_ty)#выводит 0
  35.    
  36.    bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text= 'На вашем балансе ' + str(da_zapustis_ty) +' баллов.')#выходит 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top