Closed fr13nd-x closed 7 months ago
hello, i was working with telebot using async and i wanted the handler to listen for message sent and instead i got the error:
2024-02-16 14:32:29,204 (async_telebot.py:552 MainThread) ERROR - TeleBot: "'AsyncTeleBot' object has no attribute 'register_next_step_handler'"
is there a valid attribute in AsyncTelebot to similar to register_next_step_handler
NB: i dont to use https://pytba.readthedocs.io/en/latest/sync_version/index.html#telebot.TeleBot.register_next_step_handler from Telebot rather i want to use it from AsyncTelebot context. thanks
@bot.callback_query_handler(func=lambda call: call.data == 'join_free_channel')
async def join_free_channel_callback(query):
chat_id = query.message.chat.id
await bot.edit_message_text(chat_id=chat_id, message_id=query.message.message_id,
text="Please provide your referral code:",
reply_markup=referral_link_keyboard)
# Register the next step handler to await the referral code
await bot.register_next_step_handler(query.message, process_join_free_channel)
def process_join_free_channel(message):
chat_id = message.chat.id
user_id = message.from_user.id
referral_code = message.text.strip()
print(referral_code)
if referral_code_valid(user_id, referral_code, conn):
# If the referral code is valid, add the user to the group
try:
bot.send_message(chat_id, 'You will be added to the group shortly!', reply_markup=referral_link_keyboard)
except Exception as e:
print(f"Error adding user to group: {e}")
else:
# If the referral code is not valid, prompt the user to enter a valid one
bot.send_message(chat_id, 'Invalid referral code. Please enter a valid referral code.')
# Call the function again to prompt the user for a new referral code
bot.register_next_step_handler(message, process_join_free_channel)
`
i was expecting when a user sends the code, await bot.register_next_step_handler(query.message, process_join_free_channel) would take in the code
NB: i dont to use https://pytba.readthedocs.io/en/latest/sync_version/index.html#telebot.TeleBot.register_next_step_handler from Telebot rather i want to use it from AsyncTelebot context. thanks
Use states, no steps in async
Please answer these questions before submitting your issue. Thanks!