How do we get a match check on Vkbottle's file?



  • I'm writing a bowl using vkbottle, I'd like to check the incoming e-mail on hello.txt.
    File has a sharp contents:
    Hi.
    Hi.
    Hello.
    etc.
    Like if the user wrote "Hello," bot checked this file and if there's a coincidence, "Hey you."
    At this point, the bot answers:

    @bot.on.message(text=["Привет", "Здравствуйте"])
    async def message_handler(message: Message):
    user = await bot.api.users.get(message.from_id)
    await message.answer(f"И тебе привет, {user[0].first_name}")
    

    Thank you for your help in advance, if anyone helps.



  • If you understand the question correctly, you need to expand the list of admissible messages from the users in order not to limit yourself to "hello and hello," then you should read the meanings from the text file first, and then frame them instead of "hello and hello," something like that:

    hello_messages = [] # пустой список допустимых значений
    

    with open('file.txt', encoding="utf-8" ) as f: # открываем файл
    hello_messages = f.read().split("\n") # записываем в список значения из текстового файла

    @bot.on.message(text=hello_messages) # Подставляем найденные значения
    async def message_handler(message: Message):
    user = await bot.api.users.get(message.from_id)
    await message.answer(f"И тебе привет, {user[0].first_name}")

    In addition, I would suggest that we look towards integration with the database so as not to operate with text, for example, postgreSQL, which would contain templates of possible user messages and responses, as well as other relevant information for your project.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2