Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python3上使用telebot发送没有bot.polling()的消息_Python_Python 3.x - Fatal编程技术网

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

如何在Python3上使用telebot发送没有bot.polling()的消息,python,python-3.x,Python,Python 3.x,我需要发送消息,但没有任何轮询。我的机器人不必回复它只需要发送的任何消息 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" se

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

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")
这里有两个问题:

  • 我无法调用函数send_message并传递参数“text” 在里面
  • 发送消息后,我希望我的程序能够进一步工作,而不是 查看聊天室中的消息
  • bot.send_message(msg_id,“Hello!”)
    (msg_id是人的id)将帮助您做到这一点,如果您知道人的id


    如果您没有,则可以使用
    msg.chat.id
    轻松获取,其中
    msg
    是用户发送的消息。

    到目前为止,您尝试了什么@jalazbe,我用code补充了我的问题,我怎样才能找到我的id?你可以使用这个机器人:
    @userinfobot
    ,或者发短信给你自己的机器人,然后获取
    msg.chat.id