S
S
SunnyWolf2020-06-29 10:53:29
Python
SunnyWolf, 2020-06-29 10:53:29

Code not working how to fix?

There is a code that does not work correctly, namely, for some reason, it reacts to all the words that I wrote to the bot and not only to those that are written in the code

@bot.message_handler(func=lambda message: words)
def buan(message):
  from time import time
  file = open('data.txt','r')
  TIB = file.read()
  bot.restrict_chat_member(message.chat.id, message.from_user.id, until_date=time()+(int(TIB)))


How to fix?

@bot.message_handler(func=lambda message: words)
Maybe this decorator is not meant for this, I don't know. Since I haven't been programming in Python for very long.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-06-29
@NEDOprogrammer

The decorator is wrong.

@bot.message_handler(func=lambda m: True)
def buan(message):
  if message.text not in words:
    return
  from time import time
  file = open('data.txt','r')
  TIB = file.read()
  bot.restrict_chat_member(message.chat.id, message.from_user.id, until_date=time()+(int(TIB)))

M
meaqese, 2020-06-29
@meaqese

Why did you decide to make bots without even knowing the basics of programming? Oh, the youth has gone. Read the documentation https://github.com/eternnoir/pyTelegramBotAPI , or better yet, read about lambda functions first. I think there is nothing more to explain, programmers in most cases are not psychics, so it is always necessary to read the documentation first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question