我想怎么做:調度操作,如何結束文件發送。但事實證明,該動作持續了 5 秒,然后又花了 5 秒來發送文件,而這次用戶不明白是機器人被凍結還是文件仍在發送。如何在直接發送文件之前增加操作持續時間?import telebot...def send_file(m: Message, file): bot.send_chat_action(m.chat.id, action='upload_document') bot.send_document(m.chat.id, file)
1 回答

慕桂英3389331
TA貢獻2036條經驗 獲得超8個贊
作為提比布斯。M說這是不可能的,因為所有操作都是通過 API 發送的。但線程幫助我解決了這個問題。解決方案如下所示:
from threading import Thread
def send_action(id, ac):
bot.send_chat_action(id, action=ac)
def send_doc(id, f):
bot.send_document(id, f)
def send_file(m: Message):
file = open(...)
Thread(target=send_action, args=(m.chat.id, 'upload_document')).start()
Thread(target=send_doc, args=(m.chat.id, file)).start()
...
send_file(m)
因此,可以做到動作一結束,就立即發送文件,沒有時間間隔
添加回答
舉報
0/150
提交
取消