Telegram bot api python run_daily方法

问题描述 投票:0回答:1

嘿,我试图每天运行一个电报机器人,所以我尝试了不同的事情。

updater = Updater(<botkey>, use_context=True)
dp = updater.dispatcher
dp.job_queue.run_daily(pollen, datetime.time(hour=20, minute=9), days=(0, 1, 2, 3, 4, 5, 6))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()

def pollen(update, context):
    bot.send_message(chat_id=chat_id, text='text')

updater = Updater(<botkey>, use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', creatJobs, pass_job_queue=True, pass_chat_data=True))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()

def pollen(update, context):
    bot.send_message(chat_id=chat_id, text='text')


def creatJobs(update, context):
    new_job = context.job_queue.run_daily(pollen, datetime.time(hour=20, minute=9), days=(0, 1, 2, 3, 4, 5, 6), context=chat_id)
    context.chat_data['job'] = new_job

updater = Updater(<botkey>, use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', creatJobs, pass_job_queue=True, pass_chat_data=True))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()

def pollen(update, context):
    bot.send_message(chat_id=chat_id, text='text')

def creatJobs(update, context):
    context.job_queue.run_daily(reset, pollreset, days=(0,1,2,3,4,5,6))

但没有任何效果,我正在Windows和python 3.8上进行开发导入始终相同

import logging, re, datetime, time

import telegram
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Location
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackQueryHandler)
python telegram python-telegram-bot
1个回答
0
投票

[python中没有提升(就像JavaScript中那样)。意思是,您不能在声明之前真正使用函数标识符(pollen)。

© www.soinside.com 2019 - 2024. All rights reserved.