我正在尝试在 Telegram 中进行自动发布安排。它第一次运行,但在尝试循环后出现错误:
TypeError: the first argument must be callable
我的代码:
import time
import schedule
from pyrogram import Client, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.api import functions, types
from pyrogram.api.errors import FloodWait
person1 = Client(
session_name="*cenzored*",
api_id=*cenzored*,
api_hash="*cenzored*"
)
person2 = Client(
session_name="*cenzored*",
api_id=*cenzored*,
api_hash="*cenzored*"
)
wick.start()
def Publish(session,dat,msgid,session_name):
try:
session.start()
print("[%s]Posting..." % (session_name))
session.send(
functions.messages.GetBotCallbackAnswer(
peer=session.resolve_peer("*cenzored*"),
msg_id=msgid,
data=b'publish %d' % (dat)
)
)
session.idle()
except:
print("Crashed,starting over")
schedule.every(0.3).minutes.do(Publish(person1,142129,12758, 'Dani')) // Here is the line is crashing.
schedule.every(0.3).minutes.do(Publish(person2,137351,13177, 'Wick'))
while 1:
schedule.run_pending()
time.sleep(1)
回溯:
Pyrogram v0.7.4, Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
[person1]Posting...
3: 2018-06-16 12:07:26.529829 Retrying <class 'pyrogram.api.functions.messages.get_bot_callback_answer.GetBotCallbackAnswer'>
4: 2018-06-16 12:07:42.041309 Retrying <class 'pyrogram.api.functions.messages.get_bot_callback_answer.GetBotCallbackAnswer'>
Crashed,starting over
Traceback (most recent call last):
File "C:\Users\343df\OneDrive\Desktop\Maor\python\tele\tele.py", line 35, in <module>
schedule.every(0.3).minutes.do(Publish('ss',dani,140129,12758, 'Dani'))
File "C:\Program Files (x86)\Python36-32\lib\site-packages\schedule\__init__.py", line 385, in do
self.job_func = functools.partial(job_func, *args, **kwargs)
TypeError: the first argument must be callable
基本上我的问题是在第一次之后没有运行(TypeError:第一个参数必须可调用
)并且计划每 0.3 秒运行一次。
最佳答案
根据[ReadTheDocs]: do(job_func, *args, **kwargs) ,您不必调用 Publish,而只需传递它,后跟其参数列表(调用将由schedule框架执行):
schedule.every(0.3).minutes.do(Publish, person1, 142129, 12758, "Dani")
schedule.every(0.3).minutes.do(Publish, person2, 137351, 13177, "Wick")
关于python - Telegram 类型错误 : the first argument must be callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50886560/