V
V
VoKaPTV2021-02-03 22:50:55
Python
VoKaPTV, 2021-02-03 22:50:55

Is it possible to use the discord.py library in Python to implement the idea of ​​earning points for a message?

There is a database in which something like points is recorded, there is a system for buying privileges using these points, but according to the idea, I intended to credit points through messages, the more people write the better, and with an anti-spam system (but this is later ), back to the topic with messages, searched the Internet, did not find anything similar, I hope for your help

I would like to implement a message monitoring system.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zakhar Guskov, 2021-02-04
@VoKaPTV

Look, I did it through json, but I think you will figure out how to set everything up on the database.

@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)

It turns out such an implementation that when the user writes something, exp is added to him, if exp == lvl, then lvl is updated, and exp is reset.

S
soremix, 2021-02-03
@SoreMix

It seems that python can work with numbers, so you can add a number, there is an opportunity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question