Discord Python机器人:升级系统

Discord Python机器人:升级系统,python,bots,discord,Python,Bots,Discord,所以我在谷歌上搜索了一些不同的搜索结果,并观看了这段关于为我的机器人制作水平系统的视频。基本上,机器人(PYTHON)就像一个冒险坦克游戏;游戏给你一辆坦克开始,允许你选择一张地图,移动到地图的不同区域,并使用rng来决定是否有敌人的坦克。每辆被摧毁的敌人坦克给你10点经验值。现在,在前面提到的视频中,为了添加xp,他使用消息,并在玩家进入服务器时开始播放他们的统计资料 现在,我希望我的用户在输入命令“&stats”后开始他的个人资料。在视频中,他使用json。我以前从未使用过json,所以我自

所以我在谷歌上搜索了一些不同的搜索结果,并观看了这段关于为我的机器人制作水平系统的视频。基本上,机器人(PYTHON)就像一个冒险坦克游戏;游戏给你一辆坦克开始,允许你选择一张地图,移动到地图的不同区域,并使用rng来决定是否有敌人的坦克。每辆被摧毁的敌人坦克给你10点经验值。现在,在前面提到的视频中,为了添加xp,他使用消息,并在玩家进入服务器时开始播放他们的统计资料

现在,我希望我的用户在输入命令“&stats”后开始他的个人资料。在视频中,他使用json。我以前从未使用过json,所以我自然感到困惑,但我遵循了视频的指导

我得到这个错误:

忽略on_消息中的异常
回溯(最近一次调用):文件“/home/runner/.local/share/virtualenvs/python3/lib/python3。
7/site packages/discord/client.py”,第270行,运行事件中
等待coro(*args,**kwargs)
on_消息中第72行的文件“main.py”
等待升级(用户、作者、消息通道)文件“main.py”,第435行,在升级中
lvl_端=浮动('经验**1/2')

ValueError:无法将字符串转换为float:“体验**1/2”
我已经尽了最大努力,我已经建立了一个等级系统!它是特定于服务器的,显示了进入下一个级别所需的xp量

@client.event
async def on_message(message):
    if not message.author.bot:
        print('function load')
        with open('level.json','r') as f:
            users = json.load(f)
            print('file load')
        await update_data(users, message.author,message.guild)
        await add_experience(users, message.author, 4, message.guild)
        await level_up(users, message.author,message.channel, message.guild)

        with open('level.json','w') as f:
            json.dump(users, f)
    await client.process_commands(message)




async def update_data(users, user,server):
    if not str(server.id) in users:
        users[str(server.id)] = {}
        if not str(user.id) in users[str(server.id)]:
            users[str(server.id)][str(user.id)] = {}
            users[str(server.id)][str(user.id)]['experience'] = 0
            users[str(server.id)][str(user.id)]['level'] = 1
    elif not str(user.id) in users[str(server.id)]:
            users[str(server.id)][str(user.id)] = {}
            users[str(server.id)][str(user.id)]['experience'] = 0
            users[str(server.id)][str(user.id)]['level'] = 1

async def add_experience(users, user, exp, server):
  users[str(user.guild.id)][str(user.id)]['experience'] += exp

async def level_up(users, user, channel, server):
  experience = users[str(user.guild.id)][str(user.id)]['experience']
  lvl_start = users[str(user.guild.id)][str(user.id)]['level']
  lvl_end = int(experience ** (1/4))
  
  if lvl_start < lvl_end:
      await channel.send('{} has leveled up to Level {}'.format(user.mention, lvl_end))
      users[str(user.guild.id)][str(user.id)]['level'] = lvl_end


@client.command(aliases = ['rank','lvl'])
async def level(ctx,member: discord.Member = None):

    if not member:
        user = ctx.message.author
        with open('level.json','r') as f:
        users = json.load(f)
        lvl = users[str(ctx.guild.id)][str(user.id)]['level']
        exp = users[str(ctx.guild.id)][str(user.id)]['experience']

        embed = discord.Embed(title = 'Level {}'.format(lvl), description = f"{exp} XP " ,color = discord.Color.green())
        embed.set_author(name = ctx.author, icon_url = ctx.author.avatar_url)
        await ctx.send(embed = embed)
    else:
      with open('level.json','r') as f:
          users = json.load(f)
      lvl = users[str(ctx.guild.id)][str(member.id)]['level']
      exp = users[str(ctx.guild.id)][str(member.id)]['experience']
      embed = discord.Embed(title = 'Level {}'.format(lvl), description = f"{exp} XP" ,color = discord.Color.green())
      embed.set_author(name = member, icon_url = member.avatar_url)

      await ctx.send(embed = embed)
@client.event
异步def on_消息(消息):
如果不是message.author.bot:
打印('函数加载')
将open('level.json','r')作为f:
users=json.load(f)
打印('文件加载')
等待更新_数据(用户、message.author、message.guild)
等待添加经验(用户,message.author,4,message.guild)
等待升级(用户、消息.作者、消息.频道、消息.公会)
将open('level.json','w')作为f:
json.dump(用户,f)
等待客户端处理命令(消息)
异步def更新_数据(用户、用户、服务器):
如果用户中没有str(server.id):
用户[str(server.id)]={}
如果用户[str(server.id)]中没有str(user.id):
用户[str(server.id)][str(user.id)]={}
用户[str(server.id)][str(user.id)]['experience']=0
用户[str(server.id)][str(user.id)]['level']=1
elif not str(user.id)在用户[str(server.id)]中:
用户[str(server.id)][str(user.id)]={}
用户[str(server.id)][str(user.id)]['experience']=0
用户[str(server.id)][str(user.id)]['level']=1
异步def添加体验(用户、用户、exp、服务器):
用户[str(user.guild.id)][str(user.id)]['experience']+=exp
异步def级别(用户、用户、通道、服务器):
经验=用户[str(user.guild.id)][str(user.id)]['experience']
lvl_start=users[str(user.guild.id)][str(user.id)]['level']
第二层=内部(经验**(1/4))
如果lvl_开始