home
search
help
profile
liking the experience? our app is even better
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now  
showing results for how to make a leveling system with discord py
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}!')
upvote
downvote
source
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}!')
63
upvote
downvote
queries leading to this page
level discord pydiscord leveling bot pythonleveling system discord pyhow to crate exp system discord pyhow to make a leveling system in discord py leveling system discord pydiscord py level systemdiscord py levelsdiscord py level updiscord py how like level systemdiscord py easy level systemlevel system discord pydiscord py leveling system simple leveling discord pylevelling up system discord pydiscord py levelling systemdiscord py simple level systemlevelling code for discord bots pythondiscord py level botow to make a leveling system discord pydiscord py leveling systemleveling bot discord pyhow to add leveling system in discord pylevelling system discord py codelevel system discord pydiscord py leveling system code mee6discord py level systembest leveling system discord pydiscord python level systemdiscord py level system tutorialleveling system discord py pypidiscord py levelsystemdiscord py levelsdiscord py level system botdiscord py leveling system swastichow to make a level system in discord pyhow to make a level system discord pydiscord py level system formuladiscord py level level up discord python botdiscord py leveling commanddiscord py top levelshow to code a level system discord bot pythonlevels system discord pydiscord 2cpy level systemdiscord py level system full codehow to make a levelling system for a discord bot using pymake leveling system discord pysystem discord pyhow ot make a level system discord pydiscord python bot level systemlevels discord pylevelling system discord py