discord py leveling system

Solutions on MaxInterview for discord py leveling system by the best coders in the world

showing results for - "discord py leveling system"
Matilda
14 Jul 2017
1@client.event
2async def on_member_join(member):
3    with open('users.json', 'r') as f:
4        users = json.load(f)
5
6    await update_data(users, member)
7
8    with open('users.json', 'w') as f:
9        json.dump(users, f)
10
11
12@client.event
13async def on_message(message):
14    if message.author.bot == False:
15        with open('users.json', 'r') as f:
16            users = json.load(f)
17
18        await update_data(users, message.author)
19        await add_experience(users, message.author, 5)
20        await level_up(users, message.author, message)
21
22        with open('users.json', 'w') as f:
23            json.dump(users, f)
24
25    await client.process_commands(message)
26
27
28async def update_data(users, user):
29    if not f'{user.id}' in users:
30        users[f'{user.id}'] = {}
31        users[f'{user.id}']['experience'] = 0
32        users[f'{user.id}']['level'] = 1
33
34
35async def add_experience(users, user, exp):
36    users[f'{user.id}']['experience'] += exp
37
38
39async def level_up(users, user, message):
40    with open('levels.json', 'r') as g:
41        levels = json.load(g)
42    experience = users[f'{user.id}']['experience']
43    lvl_start = users[f'{user.id}']['level']
44    lvl_end = int(experience ** (1 / 4))
45    if lvl_start < lvl_end:
46        await message.channel.send(f'{user.mention} has leveled up to level {lvl_end}')
47        users[f'{user.id}']['level'] = lvl_end
48
49@client.command()
50async def level(ctx, member: discord.Member = None):
51    if not member:
52        id = ctx.message.author.id
53        with open('users.json', 'r') as f:
54            users = json.load(f)
55        lvl = users[str(id)]['level']
56        await ctx.send(f'You are at level {lvl}!')
57    else:
58        id = member.id
59        with open('users.json', 'r') as f:
60            users = json.load(f)
61        lvl = users[str(id)]['level']
62        await ctx.send(f'{member} is at level {lvl}!')
queries leading to this page
leveling system discord pydiscord py level system formulaleveling system discord pyleveling system discord py pypihow to make a levelling system for a discord bot using pysimple leveling discord pylevelling system discord py codehow to make a level system in discord pydiscord py leveling system code mee6how ot make a level system discord pyhow to make a level system discord pydiscord py leveling system swastichow to crate exp system discord pylevelling system discord pydiscord py level system botdiscord py level system tutorialhow to add leveling system in discord pylevelling up system discord pyhow to make a leveling system discord pydiscord py level discord py levelling systemlevelling code for discord bots pythondiscord py level bothow to code a level system discord bot pythonlevel discord pydiscord py simple level systemdiscord py how like level systempoint 2fleveling system discord pydiscord python level systemdiscord leveling bot pythondiscord py easy level systemdiscord py leveling systemdiscord py level updiscord python bot level systemhow to make a leveling system with discord pylevel system discord pyleveling bot discord pylevel system discord pydiscord py levelsdiscord py leveling commandow to make a leveling system discord pydiscord py level systemdiscord py leveling system discord py level systemdiscord py level system full codehow to make a leveling system in discord py best leveling system discord pydiscord 2cpy level systemlevel up discord python botmake leveling system discord pydiscord py leveling system