类型错误:对象 NoneType 不能在"等待"表达式(机器人)中使用



我正在编写一个机器人程序,可以向用户提问。我在课堂对象中给出的答案是我后来创建的。在进行用户操作结束时;发送答案";。用户按下按钮,我将数据从对象传输到数据库。在那一刻,我得到了type_error:

TypeError:对象NoneType不能用于'await'表达式

我检查我的物品——它不是空的。我在此处添加代码:
主文件(将用户数据传输到数据库的位置(
@dp.callback_query_handler(lambda c: c.data == 'send')
def send_data_to_base():
if not db.user_exist(storage.user_id) == False:
db.add_new_user(storage.user_id, storage.gender, storage.age, storage.salary, storage.gov_rate, 
storage.city_condition, storage.level_of_development)

数据库代码:

import sqlite3
class SQLighter:
def __init__(self, database):
self.connection = sqlite3.connect(database)
self.cursor = self.connection.cursor()
def get_info(self):
with self.connection:
return self.cursor.execute("SELECT * FROM `answers`").fetchall()
def user_exist(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT * FROM `answers` WHERE `user_id` = ?", (user_id,)).fetchall()
return bool(len(result))
def add_new_user(self, user_id, gender, age, salary, gov_rate, city_condition, level_of_development):
with self.connection:
return self.cursor.execute("INSERT INTO `answers` (`user_id`, `gender`, `age`, `salary`, `gov_rate`, `city_condition`, `level_of_development`) VALUES(?,?,?,?,?,?,?)", (user_id, gender, age, salary, gov_rate, city_condition, level_of_development))

PS:我正在使用aiogram库。

在调用add_new_user函数时,我不得不使函数异步并使用等待

@dp.callback_query_handler(text='send')
async def send_data_to_base(query: CallbackQuery):
... 
if not db.user_exist(storage.user_id):
await db.add_new_user(storage.user_id, storage.gender, storage.age, storage.salary, storage.gov_rate, storage.city_condition, storage.level_of_development)

最新更新