【发布时间】:2021-06-05 11:55:27
【问题描述】:
我需要开始向 TG 组发送通知,在此之前我想连续运行一个函数,该函数将查询 API 并将数据存储在 DB 中。在此功能运行时,我希望能够发送通知(如果它们在数据库中可用):
这是我的代码:
import telegram
from telegram.ext import Updater,CommandHandler, JobQueue
token = "tokenno:token"
bot = telegram.Bot(token=token)
def start(update, context):
context.bot.send_message(chat_id=update.message.chat_id,
text="You will now receive msgs!")
def callback_minute(context):
chat_id = context.job.context
# Check in DB and send if new msgs exist
send_msgs_tg(context, chat_id)
def callback_msgs():
fetch_msgs()
def main():
JobQueue.run_repeating(callback_msgs, interval=5, first=1, context=None)
updater = Updater(token,use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start",start, pass_job_queue=True))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
这段代码给了我错误: 类型错误:run_repeating() 缺少 1 个必需的位置参数:'callback'
任何帮助将不胜感激
【问题讨论】:
标签: telegram-bot python-telegram-bot py-telegram-bot-api