How can I send message without bot.polling() using telebot on Python3

Viewed 525

I need to send message but without any polling. My bot don't have to reply to any message It just needs to send.

import telebot


bot = telebot.TeleBot("TOKEN")
@bot.message_handler(commands=['start'])


def send_message(message, text):
    bot.send_message(message.from_user.id, text)

text = "Text that I want to be sent"
send_message(text)
bot.polling()

print("Message has been sent")

Here is two problems:

  1. I can't call a function send_message and pass an argument "text" in it
  2. After sending a message I want my program to work further, and not check the chat for messages
1 Answers

bot.send_message(msg_id, "Hello!") (msg_id is person's id) will help you do that if you know the person's id.

If you don't, it is easily obtainable using msg.chat.id where msg is a message sent by the user.

Related