电报价格机器人 - 函数循环

telegram price bot - function loop

我正在尝试制作电报价格机器人,但我 运行 遇到了问题。 工作正常,但我无法将机器人设置为每 5 分钟(或更长时间)向我发送更新价格。

有什么解决办法吗? 谢谢!

我的代码

import telegram
from telegram.ext import Updater
from telegram.ext import CommandHandler
from tracker import get_prices

telegram_bot_token = "mybot"

updater = Updater(token=telegram_bot_token, use_context=True)
dispatcher = updater.dispatcher


def start(update, context):
    chat_id = update.effective_chat.id
    message = ""

    crypto_data = get_prices()
    for i in crypto_data:
        coin = crypto_data[i]["coin"]
        price = crypto_data[i]["price"]
        change_day = crypto_data[i]["change_day"]
        change_hour = crypto_data[i]["change_hour"]
        message += f" {coin}={price:,.5f}$ \nHour Change: {change_hour:.3f}%\nDay Change: {change_day:.3f}%\n\n"

    context.bot.send_message(chat_id=chat_id, text=message)


dispatcher.add_handler(CommandHandler("start", start))
updater.start_polling()

使用不同的机器人,例如@GroupHelpBot,它具有自动执行的内置功能。更多详情请同时查看: