有这样的代码:
import disnake
from disnake.ext import commands
import ujson
def load_database():
with open('DB.json', 'r') as file:
return ujson.load(file)
def save_database(data):
with open('DB.json', 'w') as file:
ujson.dump(data, file, indent=4, escape_forward_slashes=False)
@bot.slash_command(name="register", description="Регистрирует участника для использования игр")
async def register(inter: disnake.AppCmdInter):
username = str(inter.author.name)
userID = str(inter.author.id)
data = load_database()
for player in range(len(data["players"])):
if userID != data["players"][player]["id"]:
data["players"].append({"id": userID, "name": username, "balance": 1000})
save_database(data)
await inter.send("Вы успешно зарегистрированы!", ephemeral=True)
else:
await inter.send("Вы были зарегестрированы ранее!", ephemeral=True)
数据库为 JSON 文件:
{
"players": [
{
"id": "1234567890",
"name": "ivan",
"balance": 1000
},
{
"id": "0987654321",
"name": "vasya",
"balance": 500
}
]
}
当您输入命令时,机器人会写入:您之前已注册!并在您成功注册后立即!
如何实现一个系统来检查您是否在数据库中?
PS:我坐了好几个小时了还是没明白=(