如何让Python-Telegram_bot在没有收到命令的情况下发送消息?
How to make Python-Telegram_bot send a message without getting a commad?
我正在使用 Python-Telegram-bot 制作电报机器人。我想让它向一个特定的用户(在这种情况下是我自己)发送一条消息到 select 一个选项。之后,它应该将该选项作为命令并照常工作。但 30 分钟后......它应该向我发送相同的消息,让我像以前一样选择一个选项。我怎样才能工作?
def start(update: Update, context: CallbackContext) -> None:
user = update.message.from_user.username
print(user)
context.bot.send_message(chat_id=update.effective_chat.id, text= "Choose an option. ('/option1' , '/option 2', '/...')")
def main():
updater = Updater("<MY-BOT-TOKEN>", use_context=True)
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
我想 运行 不获取 /start 命令(更新)。但在此之后...将有正常的功能会得到更新,30 分钟后我想 运行 这个“开始”功能再次没有得到更新。
您可以从更新程序或调度程序中获取 bot
对象:
updater = Updater('<bot-token>')
updater.bot.sendMessage(chat_id='<user-id>', text='Hello there!')
# alternative:
updater.dispatcher.bot.sendMessage(chat_id='<user-id>', text='Hello there!')
我正在使用 Python-Telegram-bot 制作电报机器人。我想让它向一个特定的用户(在这种情况下是我自己)发送一条消息到 select 一个选项。之后,它应该将该选项作为命令并照常工作。但 30 分钟后......它应该向我发送相同的消息,让我像以前一样选择一个选项。我怎样才能工作?
def start(update: Update, context: CallbackContext) -> None:
user = update.message.from_user.username
print(user)
context.bot.send_message(chat_id=update.effective_chat.id, text= "Choose an option. ('/option1' , '/option 2', '/...')")
def main():
updater = Updater("<MY-BOT-TOKEN>", use_context=True)
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
我想 运行 不获取 /start 命令(更新)。但在此之后...将有正常的功能会得到更新,30 分钟后我想 运行 这个“开始”功能再次没有得到更新。
您可以从更新程序或调度程序中获取 bot
对象:
updater = Updater('<bot-token>')
updater.bot.sendMessage(chat_id='<user-id>', text='Hello there!')
# alternative:
updater.dispatcher.bot.sendMessage(chat_id='<user-id>', text='Hello there!')