我想在discord.py机器人中制作一个关卡系统,但我总是遇到这些错误,而且我不知道该如何解决
void loadData() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
final todoArray = _decodeTodoData(sharedPreferences.getStringList("savedTodo"))
//This is your array :) -> todoArray
}
List<Todo> _decodeTodoData(List<String> todos) {
try {
//Transforming List<String> to Json
var result = todos.map((v) => json.decode(v)).toList();
//Transforming the Json into Array<Todo>
var todObjects = result.map((v) => Todo.fromJson(v)).toList();
return todObjects;
} catch (error) {
return [];
}
}
}
同时显示的错误是: 函数调用中参数“ server”没有值
编辑: Update_data的定义如下:
@bot.event
async def on_member_join(member):
####the first error occurs here on update_data####
await update_data(users, member)
@bot.event
async def on_message(message):
with open("userslvl.json", "r") as f:
users = json.load(f)
if message.author.bot:
return
if message.channel.is_private:
return
else:
await update_data(users, message.author, message.server)
number = random.randint(5,10)
####the second error occurs here on add_experience####
await add_experience(users, message.author, number, message.server)
await level_up(users, message.author, message.channel, message.server)
with open("userslvl.json", "w") as f:
json.dump(users, f)
await bot.process_commands(message)
和add_experience的定义如下:
async def update_data(users, user, server):
if not user.id + "-" + server.id in users:
users[user.id + "-" + server.id] = {}
users[user.id + "-" + server.id]["experience"] = 0
users[user.id + "-" + server.id]["level"] = 1
users[user.id + "-" + server.id]["last_message"] = 0