如何在Python3上使用telebot发送没有bot.polling()的消息

2024-10-05 02:04:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要发送消息,但没有任何轮询。我的机器人不必回复它只需要发送的任何消息

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")

这里有两个问题:

  1. 我无法调用函数send_message并传递参数“text” 在里面
  2. 发送消息后,我希望我的程序能够进一步工作,而不是 查看聊天室中的消息

Tags: textimporttokensend消息messagedefbot

热门问题