我真的不知道怎么解释,所以我会解释我要做什么
.profile <GrowID>
,插入json文件中的GrowID李>这是我现在拥有的
命令模板
@client.command(aliases=["p"])
async def profile(ctx, GrowID=None):
with open('account.json', 'r') as f:
account = json.load(f)
if GrowID == None:
user = ctx.author
elif not GrowID == None:
user = client.get_user(GrowID.user_id)
if str(user.id) in account:
# <Codes>
我的数据在account.json
{
"811510359289495572": {
"Premium": false,
"GrowID": "Dec7h7alker",
"Character": "Default",
"Level": 1,
"XP": 0,
"XPLevel": 150,
"Gems": 0,
"World Locks": 0,
"Diamond Locks": 0,
"Growtokens": 0
}
}
命令添加数据
@client.command()
async def start(ctx):
with open('account.json', 'r') as f:
account = json.load(f)
user = ctx.author
if str(user.id) in account:
await ctx.send("Your account has already existed!")
elif str(user.id) not in account:
account[str(user.id)] = {}
account[str(user.id)]["Premium"] = False
account[str(user.id)]["GrowID"] = user.name
account[str(user.id)]["Character"] = "Default"
account[str(user.id)]["Level"] = 1
account[str(user.id)]["XP"] = 0
account[str(user.id)]["XPLevel"] = 150
account[str(user.id)]["Gems"] = 0
account[str(user.id)]["World Locks"] = 0
account[str(user.id)]["Diamond Locks"] = 0
account[str(user.id)]["Growtokens"] = 0
with open('account.json', 'w') as f:
json.dump(account, f, indent=4)
# <codes (not needed cuz its just sending message)>
好了
我真的不明白问题出在哪里,因为正如评论中已经提到的那样,您可以使用已经存在的代码从用户检索数据
但是对于这一点,我们首先假设
GrowID
依赖于discord.Member
,否则它将不起作用然后我们在上面构建我们的命令:
然后将向您发送有关该用户的以下信息:
为了让这个问题更加用户友好,需要你的知识,因为这与问题无关
命令的工作原理:
相关问题 更多 >
编程相关推荐