Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.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
如何在Python电报bot中使用Jobqueue_Python_Python 3.x_Telegram Bot_Python Telegram Bot_Job Queue - Fatal编程技术网

如何在Python电报bot中使用Jobqueue

如何在Python电报bot中使用Jobqueue,python,python-3.x,telegram-bot,python-telegram-bot,job-queue,Python,Python 3.x,Telegram Bot,Python Telegram Bot,Job Queue,我已经能够通过阅读作业队列非常容易地创建一个机器人,但是作业队列没有按照它所写的那样工作。run\u daily方法使用datetime.time对象在特定时间发送消息,但此代码既不执行发送消息的任务,也不显示任何错误。它一直在跑 import datetime from telegram import bot from telegram.ext import Updater def callback_minute(bot, job): bot.s

我已经能够通过阅读作业队列非常容易地创建一个机器人,但是作业队列没有按照它所写的那样工作。
run\u 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()
来自telegram.ext导入更新程序,CommandHandler
def每日作业(机器人、更新、作业队列):
“”“在周一、周二、周三、周四、周五运行=元组(范围(5))”
bot.send_message(chat_id=,text='Setting a daily notifications!')
t=datetime.time(10,00,00,000000)
作业队列。每天运行(通知指派者,t,天=元组(范围(5)),上下文=更新)
def通知_受让人(机器人、作业):
bot.send_message(chat_id=,text=“Some text!”)
updater=updater()
add_handler(CommandHandler('notify',daily_job,pass_job_queue=True))
updater.start_polling()
并告诉bot
/notify
from的简单用法示例

/start
命令将启动作业队列,并以5秒的间隔发送消息,可通过
/stop
命令停止队列。

使用以下代码:

from telegram.ext import CommandHandler, Updater

my_token = 'YOUR TOKEN'
updater = Updater(my_token, use_context=True)
job_queue = updater.job_queue

def send_message_job(context):
    context.bot.send_message(chat_id='@YOUR CHANELL ID',text='job executed')

job_queue.run_repeating(send_message_job,interval=10.0,first=0.0)

您好,您能解决这个问题吗,tzinfo默认为UTC,因此它与IST不匹配?@Shubh添加5H30分钟:)
from telegram.ext import CommandHandler, Updater

my_token = 'YOUR TOKEN'
updater = Updater(my_token, use_context=True)
job_queue = updater.job_queue

def send_message_job(context):
    context.bot.send_message(chat_id='@YOUR CHANELL ID',text='job executed')

job_queue.run_repeating(send_message_job,interval=10.0,first=0.0)