N
N
NOblo2020-06-15 20:56:26
Python
NOblo, 2020-06-15 20:56:26

TeleBot module, need a function, how?

You can write a def function for the telebot module that:
If it is activated Will a person write something?

def hello():
    bot.send_message(message.chat.id, "hello")
#такие не работают, ошибкц дает, message нету

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Pokrovsky, 2020-06-15
@Makaroshka007

Can.

S
soremix, 2020-06-15
@SoreMix

off documentation for what?

@bot.message_handler(func=lambda m: True)
def echo_all(message):
  bot.reply_to(message, message.text)

# Handles all text messages that contains the commands '/start' or '/help'.
@bot.message_handler(commands=['start', 'help'])
def handle_start_help(message):
  pass

# Handles all sent documents and audio files
@bot.message_handler(content_types=['document', 'audio'])
def handle_docs_audio(message):
  pass

# Handles all text messages that match the regular expression
@bot.message_handler(regexp="SOME_REGEXP")
def handle_message(message):
  pass

# Handles all messages for which the lambda returns True
@bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain', content_types=['document'])
def handle_text_doc(message):
  pass

# Which could also be defined as:
def test_message(message):
  return message.document.mime_type == 'text/plain'

@bot.message_handler(func=test_message, content_types=['document'])
def handle_text_doc(message):
  pass

# Handlers can be stacked to create a function which will be called if either message_handler is eligible
# This handler will be called if the message starts with '/hello' OR is some emoji
@bot.message_handler(commands=['hello'])
@bot.message_handler(func=lambda msg: msg.text.encode("utf-8") == SOME_FANCY_EMOJI)
def send_something(message):
    pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question