There are inline buttons "like", "dislike" Telegram bot. How do I change the value of a button after clicking on it?
I decided to put the variables quant1 and quant2 in the rows of buttons. But I don't know how to change them by clicking on the button. I made this code. But when you click on it, an error pops up:
File "bottwo.py", line 86, in callback_vote_action quant1 += 1 TypeError: can only concatenate tuple (not "int") to tuple
It seems clear that he does not want to work with the numbers in the string, but how then to make it work?\
vote_cb = CallbackData('vote', 'action') # vote:<action>
likes = {} # user_id: amount_of_likes
def get_keyboard():
quant1 = 0
quant2 = 0
butlike = types.InlineKeyboardButton(' ' + str(quant1), callback_data=vote_cb.new(action='up'))
butdilike = types.InlineKeyboardButton(' ' + str(quant2), callback_data=vote_cb.new(action='down'))
return types.InlineKeyboardMarkup().row(butlike, butdilike)
@dp.callback_query_handler(vote_cb.filter(action=['up', 'down']))
async def callback_vote_action(query: types.CallbackQuery, callback_data: dict):
logging.info('Получил данные обратного вызова: %r', callback_data) # callback_data содержит всю информацию из данных обратного вызова
await query.answer() # Не забудьте ответить на запрос обратного вызова как можно скорее
callback_data_action = callback_data['action']
likes_count = likes.get(query.from_user.id, 0)
if callback_data_action == 'up':
likes_count += 1
for quant1 in get_keyboard():
quant1 += 1
if likes_count == 1:
pass
else:
likes_count -= 1
for quant2 in get_keyboard():
quant2 += 1
if likes_count == 0:
pass
likes[query.from_user.id] = likes_count # обновление количества лайков в хранилище
0
1 answers
0
Author: Ozeranskiy S., 2020-07-20 20:09:28