Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telegram bot does not respond to inlinebuttons #20

Open
rghWoagh opened this issue Nov 28, 2023 · 0 comments
Open

telegram bot does not respond to inlinebuttons #20

rghWoagh opened this issue Nov 28, 2023 · 0 comments

Comments

@rghWoagh
Copy link

the bot responds as expected to /start, but nothing responds to button clicks in the message

`from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackContext, CallbackQueryHandler, Application
import telegram.ext
import random

current_number = 0
game_active = False

async def start(update: Update, context: CallbackContext) -> None:
global current_number
global game_active

current_number = random.randint(1, 100)
game_active = True

keyboard = [
    [InlineKeyboardButton("Больше", callback_data='more')],
     [InlineKeyboardButton("Меньше", callback_data='less')]
]

reply_markup = InlineKeyboardMarkup(keyboard)

await update.message.reply_text(f"Загадано число {current_number} Больше или меньше?", reply_markup=reply_markup)

async def check_guess(update: Update, context: CallbackContext) -> None:
global current_number
global game_active

query = update.callback_query
choice = query.data

new_number = random.randint(1, 100)

if (choice == 'more' and new_number > current_number) or (choice == 'less' and new_number < current_number):
    message = "Вы выиграли! Вот следующее число: {}".format(new_number)
else:
    message = "Вы проиграли. Попробуйте снова. Вот следующее число: {}".format(new_number)

current_number = new_number
game_active = False

await query.edit_message_text(text=message)

def main() -> None:
application = Application.builder().token('token').build()
application.add_handler(CommandHandler('start', start))
application.run_polling()

if name == 'main':
import asyncio
asyncio.run(main())`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant