Discord
- 2 ответа
- 0 вопросов
1
Вклад в тег
@client.event
async def on_message(message):
with open('data.json', mode='r') as file:
data = json.load(file)
client_id = str(message.author.id)
# The function checks users in 'data' variable.
async def update_data(user):
if user not in data:
data[user] = {}
data[user]['lvl'] = 1
data[user]['exp'] = 0
# The function gives exp to users, when they send messages.
async def add_exp(user):
data[user]['exp'] += 0.1
# The function gives a new level once exp reaches new level-milestone.
async def add_lvl(user):
if data[user]['exp'] >= data[client_id]['lvl']:
data[user]['exp'] = 0
data[user]['lvl'] += 1
emb = discord.Embed(description=f'{message.author} Повысил свой уровень!', color=0xf2db0a)
await message.channel.send(embed=emb)
await update_data(client_id)
await add_exp(client_id)
await add_lvl(client_id)
with open('data.json', mode='w') as file:
json.dump(data, file)