运行时警告:启用tracemalloc以获取对象分配回溯?

问题描述 投票:0回答:1

我正在构建一个 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
并获得有效的代码?

(请向初学者解释)

python telegram telebot tracemalloc
1个回答
0
投票

bot.polling
更改为
bot.polling()

© www.soinside.com 2019 - 2024. All rights reserved.