我收到此錯誤的代碼部分。
@bot.message_handler(commands=['redeemcode'])
def get_code(message):
code = bot.send_message(chatid, "Send the Code to Redeem")
bot.register_next_step_handler(code, claimcode)
async def claimcode(message):
code = str(message.text)
print(code)
await client.redeem_code(code)
我得到的錯誤。
Microsoft Windows [Version 10.0.19044.1645]
(c) Microsoft Corporation. All rights reserved.
D:\Genshin Bot>C:/Python310/python.exe "d:/Genshin Bot/genshinbot.py"
C:\Python310\lib\site-packages\telebot\util.py:89: RuntimeWarning: coroutine 'claimcode' was never awaited
task(*args, **kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
有人可以幫忙告訴代碼有什么問題嗎
uj5u.com熱心網友回復:
您正在嘗試在普通函式中呼叫協程。使用asyncio.run. 要了解有關協程和任務的更多資訊,可以參考此鏈接:https ://docs.python.org/3/library/asyncio-task.html 。
上面的代碼片段可以更改為:
import asyncio
@bot.message_handler(commands=['redeemcode'])
def get_code(message):
code = bot.send_message(chatid, "Send the Code to Redeem")
bot.register_next_step_handler(code, asyncio.run(claimcode()))
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/485513.html
標籤:Python python-3.x 电报 遥控机器人
