我正在构建一个 Telegram 机器人。此代码正在运行:
import telebot
bot = telebot.TeleBot("TOKEN")
@bot.message_handler(func=lambda newMessage: True)
def main(newMessage):
print(newMessage)
bot.polling()
但我需要它在
main()
函数中,await
是另一个函数 print(newMessage)
。那我应该把def
改为async def
。
import telebot
bot = telebot.TeleBot("TOKEN")
@bot.message_handler(func=lambda newMessage: True)
async def main(newMessage):
print(newMessage)
bot.polling()
我替换了它,然后收到此错误:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
并且代码不起作用......
如何在没有错误的情况下用
def
替换 async def
并获得有效的代码?
(请向初学者解释)
将
bot.polling
更改为 bot.polling()
。