Обработчик не видит сообщения айограммыPython

Программы на Python
Ответить
Anonymous
 Обработчик не видит сообщения айограммы

Сообщение Anonymous »

Вот проблема: бот не реагирует на клавиатуру или текст, например «1-7» или «х2», в режимах: «мистер» и «дабл». Он отвечает только в том случае, если я отправляю сообщение в ответ на сообщение бота, в котором была вызвана клавиатура. В режимах «колесо» и «кубики» я могу просто ввести «19-36» или «1», и ставка будет определена без ответа на сообщение. Почему это?
Клавиатуры:

Код: Выделить всё

def create_keyboard_wheel():
return types.ReplyKeyboardMarkup(
keyboard=[
[types.KeyboardButton(text="1-18"), types.KeyboardButton(text="19-36")],
[types.KeyboardButton(text="Черное"), types.KeyboardButton(text="Красное")],
[types.KeyboardButton(text="Четное"), types.KeyboardButton(text="Нечетное")],
[types.KeyboardButton(text="1-12"), types.KeyboardButton(text="13-22"), types.KeyboardButton(text="23-36")],
[types.KeyboardButton(text="Число")],
[types.KeyboardButton(text="Банк"), types.KeyboardButton(text="Профиль")]
],
resize_keyboard=True,
one_time_keyboard=False
)

def create_keyboard_double():
return types.ReplyKeyboardMarkup(
keyboard=[
[types.KeyboardButton(text="2x"), types.KeyboardButton(text="3x")],
[types.KeyboardButton(text="5x"), types.KeyboardButton(text="40x")],
[types.KeyboardButton(text="Банк"), types.KeyboardButton(text="Профиль")]
],
resize_keyboard=True,
one_time_keyboard=False
)

def create_keyboard_mr():
return types.ReplyKeyboardMarkup(
keyboard=[
[types.KeyboardButton(text="Красное"), types.KeyboardButton(text="Черное")],
[types.KeyboardButton(text="1-7"), types.KeyboardButton(text="Число"), types.KeyboardButton(text="8-14")],
[types.KeyboardButton(text="Четное"), types.KeyboardButton(text="Нечетное")],
[types.KeyboardButton(text="Банк"), types.KeyboardButton(text="Профиль")]
],
resize_keyboard=True,
one_time_keyboard=False
)

def create_keyboard_dice():
return types.ReplyKeyboardMarkup(
keyboard=[
[types.KeyboardButton(text="1"), types.KeyboardButton(text="2"), types.KeyboardButton(text="3")],
[types.KeyboardButton(text="4"), types.KeyboardButton(text="5"), types.KeyboardButton(text="6")],
[types.KeyboardButton(text="Четное"), types.KeyboardButton(text="Нечетное")],
[types.KeyboardButton(text="Банк"), types.KeyboardButton(text="Профиль")]
],
resize_keyboard=True,
one_time_keyboard=False
)

async def create_dynamic_keyboard(game_choice):
game_choice = game_choice.lower().replace(' ', '_')

if game_choice == "wheel":
return create_keyboard_wheel()
elif game_choice == "mr":
return create_keyboard_mr()
elif game_choice == "dice":
return create_keyboard_dice()
elif game_choice == "double":
return create_keyboard_double()
else:
return types.ReplyKeyboardMarkup(
resize_keyboard=True, one_time_keyboard=False
)

#Keyboard recall:

@dp.callback_query_handler(lambda c: c.data and c.data.startswith('select_game_'))
async def process_game_selection(callback_query: types.CallbackQuery):
game_choice = callback_query.data.replace('select_game_', '').replace('_', ' ').lower()

chat_id = callback_query.message.chat.id

async with aiosqlite.connect("database/database.db") as db:
await db.execute("UPDATE chats SET game_selected = ?, game = ? WHERE chat_id = ?", (True, game_choice, chat_id))
await db.commit()

keyboard = await create_dynamic_keyboard(game_choice)

await callback_query.message.answer(f"Вы выбрали игру: {game_choice}.  Теперь вы можете начать делать ставки.\n\n", reply_markup=keyboard)
Обработчик текста:**

Код: Выделить всё

@dp.message_handler(lambda message: message.text in ["1-7", "8-14", "Четное", "Нечетное", "Число", "Черное", "Красное", "1-18", "19-36", "1-12", "13-22", "23-36", "1", "2", "3", "4", "5", "6", "2x", "3x", "5x", "40x"])
async def place_bet(message: types.Message):
global betting_active, active_bets

bet_type = message.text
user_id = message.from_user.id
chat_id = message.chat.id
await register_user(user_id, message.from_user.username)
game_mode = await get_game_mode(chat_id)
…
Функция регистрации работника в result.py:

Код: Выделить всё

def register_handlers_result(dp: Dispatcher):
dp.register_message_handler(place_bet, lambda message: message.text in ["1-7", "8-14", "Четное", "Нечетное", "Число",           "Черное", "Красное", "1-18", "19-36", "1-12", "13-22", "23-36", "1", "2", "3", "4", "5", "6"], state="*")
В main.py:

Код: Выделить всё

result.register_handlers_result(dp)
Я добавил логгер и заметил, что он вообще не видит текст в режимах «mr» и «double», только в ответ на сообщение. Для всего один текстовый обработчик, в других режимах он видит все ставки, даже предназначенные для других режимов - выдавая об этом ошибку.
Вот как это показано. В Wheel пишу или нажимаю кнопку не отвечая на сообщение и оно продолжается. В дубле пишу без ответа - игнорирую, с ответом - продолжайте....
Скриншот:
это колесо
двойное
Я пробовал удалить все, что работает в обработчике текста, и оставить только ['x2', 'x3'...] - не работает< /p>
В общем, я много чего перепробовал. Надеюсь на вашу помощь!

Подробнее здесь: https://stackoverflow.com/questions/791 ... m-messages
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»