python - 如何在 Python-telegram-bot 中使用 Jobqueue

标签 python python-3.x telegram-bot python-telegram-bot job-queue

通过阅读docs,我可以非常轻松地制作一个机器人。但 Jobqueue 并没有按照它所写的那样工作。 run_daily 方法使用 datetime.time 对象在特定时间发送消息,但此代码既不执行发送消息的工作,也不显示任何错误。它只是继续运行

    import datetime
    from telegram import bot
    from telegram.ext import Updater
    def callback_minute(bot, job):
        bot.send_message(chat_id=475838704, text='PlEaSe wOrK!')

    def main():
        updater = Updater()
        bot = updater.bot
        job = updater.job_queue

        dispatcher = updater.dispatcher

        job.run_daily(callback_minute, time=datetime.time(6,33,00))

        updater.start_polling()
        updater.idle()

    if __name__ == '__main__':
        main()

最佳答案

也许这会有所帮助:

from telegram.ext import Updater, CommandHandler

def daily_job(bot, update, job_queue):
    """ Running on Mon, Tue, Wed, Thu, Fri = tuple(range(5)) """
    bot.send_message(chat_id=<YOUR CHAT ID>, text='Setting a daily notifications!')
    t = datetime.time(10, 00, 00, 000000)
    job_queue.run_daily(notify_assignees, t, days=tuple(range(5)), context=update)

def notify_assignees(bot, job):
    bot.send_message(chat_id=<CHAT ID>, text="Some text!")

updater = Updater(<BOT_TOKEN>)
updater.dispatcher.add_handler(CommandHandler('notify', daily_job, pass_job_queue=True))
updater.start_polling()

并对机器人说/notify

关于python - 如何在 Python-telegram-bot 中使用 Jobqueue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52556939/

相关文章:

python - 如何在Python中模拟一系列用户输入

python - pyqt4如何导入和更改绘制文本的自定义字体

python - 适用于 Windows、Python 3、64 位的 Theano 安装

python - `my_instance = MyClass(a, b).my_method(c)` 是可接受的(Pythonic)模式吗?

c# - Telegram answerInlineQuery 无法解析数字

audio - Telegram bot不会从Windows Server中的xampp服务器发送mp3文件

python - 卸载 easy_install、pip、pip3、virtualenv 和 virtualenvwrapper

python - 我将如何比较一个字符串输入是否是第二个字符串输入的前缀?

python - 安装包 Beautiful Soup 失败。错误消息是 "SyntaxError: Missing parentheses in call to ' print'"

telegram-bot - 电报机器人API Webhook上没有JSON POST数据