我正在尝试使用 Colab 中的 pyrogram 从我的机器人发送消息,但我不能使用主线程,因为 pyrogram 会认为我正在异步函数中运行我的代码,并且所有函数都变成了协程。
所以我尝试从另一个线程运行它,但问题是它在bot.start()
一个单元运行时卡住了。
当所有单元完成运行时。它会运行良好并发送消息。
编码:
from pyrogram import Client
import threading
bot=Client("Me", bot_token=BOT_TOKEN, api_id=APP_ID, api_hash=API_HASH,no_updates=True)
def main():
bot.start()
bot.send_message(chat_id="...",text="how")
bot.stop()
t=threading.Thread(target=main)
t.start()
我查看了pyrogram 模块但我不知道为什么会发生这种情况